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)
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.
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 :p Thanks
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.
Re: Some Co-ordinate help
Quote:
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.
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?
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
Re: Some Co-ordinate help
Quote:
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.
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 :D).
Re: Some Co-ordinate help
Oooh thanks for the code, i am not really entirely sure the best approach and i now see what you mean about the angles and the distance. Makes much more sense than drawing all regions and testing them :p
Personally the quickest and cleanest way i would obviously be best :D
Thanks for your help
EDIT:
Thanks Jemidiah, i did it your way and just finished. I sometimes over complicate problems and this was a classic example of that!! and thanks to Logophobic for your code on 2d graphics :)