Math Challenge!

Here's the challenge: I have 4 points of a circle: top, bottom, left and right. I don't want to draw a circle in the screen or something like that! I only want to know if a point is INSIDE the circle.

Example:

Top: 50
Bottom: -50
Left: -50
Right: 50

Does the point (60, 60) inside the circle? NO
Does the point (10, 10) inside the circle? YES

I need a function like that:

Public Function Contais(Top, Bottom, Left, Right, Point_X, Point_Y) as Boolean

Help!!

Comments

  • seancampbellseancampbell Pennsylvania, USA
    This isn't really that challenging, I learned the math in 9th grade in Highschool.

    Curiously, why are you sending Top, Bottom, Left, and Right, instead of the Center point? Smells like school-homework to me...

    [code]
    Public Function CircleContainsPoint(ByVal Top As Integer, ByVal Bottom As Integer, ByVal Left As Integer, ByVal Right As Integer, ByVal Point_X As Integer, ByVal Point_Y As Integer) As Boolean
    'This only works for Circles
    Dim CenterY As Integer = Top - ((Top - Bottom) / 2)
    Dim CenterX As Integer = Right - ((Right - Left) / 2)

    Dim Radius As Double = ((Top - Bottom) / 2)

    Dim dx As Integer = 0
    Dim dy As Integer = 0

    dx = Point_X - CenterX
    dy = Point_Y - CenterY

    Dim sumOfSquares As Integer = dx * dx + dy * dy

    Return (Radius * Radius) >= sumOfSquares
    End Function
    [/code]
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion