|
-
May 14th, 2009, 12:53 PM
#1
Thread Starter
New Member
Some Co-ordinate help
Hello,
I am creating an application for my local pub team to keep score of darts, i am using an image of a board which is then clicked per dart to register the score. I am using the co ordinates of the section on the image, for example:
double 13:
Top Left: (569 , 219)
Top Right: (595 , 294)
Bottom Left: (581 , 298)
Bottom Right: (557 , 227)
the issue being how do i mathematically calculate that say 571 , 260 is inside this range and only inside this shape?
Oh i am programming in VB.NET 2005 but i don't need code really but logic help
Last edited by TubbZ; May 17th, 2009 at 03:29 PM.
-
May 14th, 2009, 02:10 PM
#2
Member
Re: Some Co-ordinate help
Create a GraphicsPath for your Double 13 shape using the coordinates as listed - call it say gpDouble13. You can then use gpDouble13.IsVisible (571,260)
-
May 14th, 2009, 02:20 PM
#3
Re: Some Co-ordinate help
Are these sections of pies cut out by the given coordinates? If they're just some sort of 4-sided figure InertiaM's solution sounds simple and direct, though I don't use .NET.
The time you enjoy wasting is not wasted time.
Bertrand Russell
<- Remember to rate posts you find helpful.
-
May 15th, 2009, 08:14 AM
#4
Thread Starter
New Member
Re: Some Co-ordinate help
ooh thats an idea, thanks!! i have spent a few too many hours of trying to get point inside polygon formulae to work, but they all seem to be slightly wrong for the points passed so i will just have to try this instead Thanks
-
May 15th, 2009, 01:00 PM
#5
Re: Some Co-ordinate help
You're making it way too complicated. Measure the distance from center and angle from horizontal. That's all you need.
-
May 16th, 2009, 12:42 AM
#6
Re: Some Co-ordinate help
 Originally Posted by Logophobic
You're making it way too complicated. Measure the distance from center and angle from horizontal. That's all you need.
Well, again it depends if these graphics are, say, trapezoidal regions that you click, or if they're actually pie sectors.
The time you enjoy wasting is not wasted time.
Bertrand Russell
<- Remember to rate posts you find helpful.
-
May 16th, 2009, 05:59 AM
#7
Thread Starter
New Member
Re: Some Co-ordinate help
No i haven't cut the image up into shapes, i have never really touched any graphics functions in vb.net so i just considered using co-ordinates, how easy is it to create custom click able shapes?
-
May 16th, 2009, 06:30 AM
#8
Member
Re: Some Co-ordinate help
Yes, it's easy. This code should get you started :-
Code:
Option Explicit On
Option Strict On
Imports SYSTEM.Drawing.Drawing2D
Public Class Form1
Private CurrentMouseLocation As Point
Private gpDouble13 As New GraphicsPath
Public Sub New()
' This call is required by the Windows Form Designer.
InitializeComponent()
' Add any initialization after the InitializeComponent() call.
Me.SetStyle(ControlStyles.OptimizedDoubleBuffer, True)
Me.SetStyle(ControlStyles.AllPaintingInWmPaint, True)
Me.SetStyle(ControlStyles.UserPaint, True)
gpDouble13.AddPolygon(New PointF() {New PointF(569, 219), New PointF(595, 294), New PointF(581, 298), New PointF(557, 227)})
End Sub
Private Sub Form1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Click
If gpDouble13.IsVisible(CurrentMouseLocation) Then
MessageBox.Show("You clicked on Double 13")
End If
End Sub
Private Sub Form1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseMove
'store the mouse location every time the mouse moves
CurrentMouseLocation = e.Location
'repaint form
Me.Invalidate()
End Sub
Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
With e.Graphics
If gpDouble13.IsVisible(CurrentMouseLocation) Then
'mouse over double 13, paint in green
.FillPath(Brushes.Green, gpDouble13)
Else
'mouse NOT over double 13, paint in red
.FillPath(Brushes.Red, gpDouble13)
End If
.DrawPath(Pens.Black, gpDouble13)
End With
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'If PanelToStack.Bounds.IntersectsWith(New Rectangle(-51, -51, 50, 50)) = True Then
' MessageBox.Show("Hit")
'End If
End Sub
End Class
-
May 16th, 2009, 09:44 AM
#9
Re: Some Co-ordinate help
 Originally Posted by jemidiah
Well, again it depends if these graphics are, say, trapezoidal regions that you click, or if they're actually pie sectors.
There are no trapezoidal regions on a dartboard. The example given in the OP is only an approximation of the actual region and is most definitely not the best approach. Instead of trying to make trapezoids work (you would have to test each of the 82 regions until you get a hit), simply use the angle to find the base value (1 to 20) and the radius to find the multiplier (single, double, or triple). The radius will also tell you if the point is in one of the two central regions of the dartboard, or not within the scoring area at all.
-
May 16th, 2009, 12:01 PM
#10
Re: Some Co-ordinate help
I know how a dart board looks . I'd agree that procedurally generating the regions as you describe is the cleanest way to go, but I could also see someone approximating the dartboard. Hence, I've asked which way it is (twice ).
The time you enjoy wasting is not wasted time.
Bertrand Russell
<- Remember to rate posts you find helpful.
-
May 17th, 2009, 01:33 PM
#11
Thread Starter
New Member
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|