Results 1 to 11 of 11

Thread: Some Co-ordinate help

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2009
    Posts
    4

    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.

  2. #2
    Member
    Join Date
    Mar 2008
    Location
    East Kent, UK
    Posts
    34

    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)

  3. #3
    Only Slightly Obsessive jemidiah's Avatar
    Join Date
    Apr 2002
    Posts
    2,431

    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.

  4. #4

    Thread Starter
    New Member
    Join Date
    May 2009
    Posts
    4

    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

  5. #5
    Frenzied Member
    Join Date
    Jun 2006
    Posts
    1,098

    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.

  6. #6
    Only Slightly Obsessive jemidiah's Avatar
    Join Date
    Apr 2002
    Posts
    2,431

    Re: Some Co-ordinate help

    Quote Originally Posted by Logophobic View Post
    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.

  7. #7

    Thread Starter
    New Member
    Join Date
    May 2009
    Posts
    4

    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?

  8. #8
    Member
    Join Date
    Mar 2008
    Location
    East Kent, UK
    Posts
    34

    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

  9. #9
    Frenzied Member
    Join Date
    Jun 2006
    Posts
    1,098

    Re: Some Co-ordinate help

    Quote Originally Posted by jemidiah View Post
    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.

  10. #10
    Only Slightly Obsessive jemidiah's Avatar
    Join Date
    Apr 2002
    Posts
    2,431

    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.

  11. #11

    Thread Starter
    New Member
    Join Date
    May 2009
    Posts
    4

    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

    Personally the quickest and cleanest way i would obviously be best

    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
    Last edited by TubbZ; May 17th, 2009 at 03:29 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width