Results 1 to 5 of 5

Thread: [RESOLVED] [2008] Determine Point Inside Circle.

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2006
    Posts
    607

    Resolved [RESOLVED] [2008] Determine Point Inside Circle.

    Hey I am creating a simple game. But right now all I have is a simple Ball class that creates a filled circle on the screen.

    Code:
    Imports System.Drawing
    Public Class Ball
        Private GR As Graphics
    
        Private _radius As Integer
        Public Property Radius() As Integer
            Get
                Return _radius
            End Get
            Set(ByVal value As Integer)
                _radius = value
            End Set
        End Property
    
    
        Private _diameter As Integer
        Public Property Diameter() As Integer
            Get
                Return _diameter
            End Get
            Set(ByVal value As Integer)
                _diameter = value
            End Set
        End Property
    
    
        Private _color As Color
        Public Property Color() As Color
            Get
                Return _color
            End Get
            Set(ByVal value As Color)
                _color = value
            End Set
        End Property
    
    
        Private _x As Double
        Public Property x() As Double
            Get
                Return _x
            End Get
            Set(ByVal value As Double)
                _x = value
            End Set
        End Property
    
    
        Private _y As Double
        Public Property y() As Double
            Get
                Return _y
            End Get
            Set(ByVal value As Double)
                _y = value
            End Set
        End Property
    
    
    
        Public Sub New(ByVal g As Graphics)
            Diameter = 10
            Radius = Diameter / 2
            Color = Drawing.Color.Black
            x = 90
            y = 134
            GR = g
        End Sub
    
        Public Sub New(ByVal g As Graphics, ByVal d As Integer, ByVal c As Color)
            Diameter = d
            Radius = Diameter / 2
            Color = c
            GR = g
        End Sub
    
        Public Sub Draw()
            GR.DrawArc(Pens.Blue, Convert.ToInt16(x), Convert.ToInt16(y), Diameter, Diameter, 0, 360)
        End Sub
    
        Public Sub DrawFill()
            GR.FillEllipse(Brushes.BurlyWood, Convert.ToInt16(x), Convert.ToInt16(y), Diameter, Diameter)
        End Sub
    
        Public Sub Del()
            GR.FillEllipse(Brushes.White, Convert.ToInt16(x), Convert.ToInt16(y), Diameter, Diameter)
        End Sub
    
        Public Function InsideBall(ByVal x As Integer, ByVal y As Integer) As Boolean
    
    
        End Function
    
    End Class
    As you can see my InsideBall class is empty. I am getting the two x and y from the form where its being clicked, but I have no idea how to check if the click is in the circle. Looking for some guidelines on where to start.

    Also I tried drawing it on paper, but I am way to tired I guess.

  2. #2
    Smitten by reality Harsh Gupta's Avatar
    Join Date
    Feb 2005
    Posts
    2,938

    Re: [2008] Determine Point Inside Circle.

    Is (X,Y) the center point of circle?
    Show Appreciation. Rate Posts.

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2006
    Posts
    607

    Re: [2008] Determine Point Inside Circle.

    Umm in the code you see, the X, Y properties are center of the circle. While the X Y parameters in the function "InsideBall" are the click co ordinates.

    Bad naming, will change it

  4. #4
    Smitten by reality Harsh Gupta's Avatar
    Join Date
    Feb 2005
    Posts
    2,938

    Re: [2008] Determine Point Inside Circle.

    Find the distance between the radius and the point on which user clicked. If this distance is less than the radius, then it is inside the circle, if equals then on the circle else outside the circle.
    vb.net Code:
    1. 'let (mx,my) be coordinates on which user clicked
    2. '(x,y) center of circle, known to you
    3. 'radius, known to you.
    4.  
    5. 'to find the distance
    6.  
    7. Dim distance As Integer 'whatever
    8.  
    9. distance = Math.Sqrt((mx-x)*(mx-x) + (my-y)*(my-y))
    10.  
    11. If distance < Me.Radius
    12. 'Point lies inside circle
    13. 'do whatever you want to do
    14. End If
    Show Appreciation. Rate Posts.

  5. #5

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