|
-
May 21st, 2008, 04:50 PM
#1
Thread Starter
Fanatic Member
[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.
-
May 21st, 2008, 04:55 PM
#2
Re: [2008] Determine Point Inside Circle.
Is (X,Y) the center point of circle?
-
May 21st, 2008, 04:58 PM
#3
Thread Starter
Fanatic Member
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
-
May 21st, 2008, 05:16 PM
#4
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:
'let (mx,my) be coordinates on which user clicked '(x,y) center of circle, known to you 'radius, known to you. 'to find the distance Dim distance As Integer 'whatever distance = Math.Sqrt((mx-x)*(mx-x) + (my-y)*(my-y)) If distance < Me.Radius 'Point lies inside circle 'do whatever you want to do End If
-
May 21st, 2008, 06:13 PM
#5
Thread Starter
Fanatic Member
Re: [2008] Determine Point Inside Circle.
Duh Distance Formula!
Thankyou
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
|