Find if a point is inside or outside of a triangle
Find if a point is inside or outside of a circle
▲
Triangle vertex coordinates
Triangle lines equations
Test point
x
1
y
1
y =
x +
p
x
p
y
x
2
y
2
y =
x +
x
3
y
3
y =
x +
Point location:
Find if a point is inside or outside of a circle
▲
Circle equation:
( x -
)
2
+ ( y -
)
2
=
x
2
+ y
2
+
x +
y +
= 0
Test point (x ,y):
(
,
)
Point location:
Find if a point is inside or outside of a triangle
▲
Determine if a point is inside or outside of a triangle whose vertices are the points
(x
1
, y
1
), (x
2
, y
2
) and (x
3
, y
3
).
By vectors analysis - if the
cross product
of the
vectors
:
are all positive or all negative, the point is inside the triangle.
The cross product of all three pairs of the triangle sides are:
After solving the
determinants
we get the values:
k
1
= (p
x
⎯ x
1
)•(y
2
⎯ y
1
) ⎯ (p
y
⎯ y
1
)•(x
2
⎯ x
1
)
k
2
= (p
x
⎯ x
2
)•(y
3
⎯ y
2
) ⎯ (p
y
⎯ y
2
)•(x
3
⎯ x
2
)
k
3
= (p
x
⎯ x
3
)•(y
1
⎯ y
3
) ⎯ (p
y
⎯ y
3
)•(x
1
⎯ x
3
)
If all three equations are either positive or negative then the point
(p
x
, p
y
)
is inside the triangle.
If triangle is given by the
lines equations
:
y = m
1
x + b
1
y = m
2
x + b
2
y = m
3
x + b
3
Find intersection points of the sides of the triangle.
After finding the intersection points use the vector method.
Example:
given a triangle whose vertices are at (3, ⎯ 2), (1, 5) and (⎯ 3, 2) determine if the point (1, 3) is inside or outside of the triangle.
Find k
1
, k
2
and k
3
.
k
1
= (1 ⎯ 3)•(5 ⧾ 2) ⎯ (3 ⧾ 2)•(1 ⎯ 3) = ⎯ 4
k
2
= (1 ⎯ 1)•(2 ⎯ 5) ⎯ (3 ⎯ 5)•(⎯ 3 ⎯ 1) = ⎯ 8
k
3
= (1 ⧾ 3)•(⎯ 2 ⎯ 2) ⎯ (3 ⎯ 2)•(3 ⧾ 3) = ⎯ 22
Because the signs of k
1
, k
2
and k
3
are all negative the point is inside the given triangle.
The vector analysis can be applied to any convex polygon that has n sides to determine if the point p is inside the polygon.
k
1
= (p
x
⎯ x
1
)•(y
2
⎯ y
1
) ⎯ (p
y
⎯ y
1
)•(x
2
⎯ x
1
)
···
k
n-1
= (p
x
⎯ x
n-1
)•(y
n
⎯ y
n-1
) ⎯ (p
y
⎯ y
n-1
)•(x
n
⎯ x
n-1
)
···
k
n
= (p
x
⎯ x
n
)•(y
1
⎯ y
n
) ⎯ (p
y
⎯ y
n
)•(x
1
⎯ x
n
)
This calculation should apply to each side of the polygon from 1 to n. If the signs of all k's are the same positive or negative then the point p is inside the polygon.
Note: this method applies only to convex polygons.
Find if a point is inside or outside of a circle
▲
How to determine if a point (p
x
, p
y
) is inside or outside of a circle given by the form
(x ⎯ a)
2
⧾ (y ⎯ b)
2
= r
2
The center of the circle is at point: (a, b)
The radius of the circle is: r
Find the distance of point (p
x
, p
y
) from the center of the circle by
the equation:
If the distance is less then the radius then the point is inside the circle.
If the circle equation is of the form
x
2
⧾ y
2
⧾ Ax ⧾ By ⧾ C = 0
The center of the circle is at point:
The radius of the circle is:
Find the distance of point (p
x
, p
y
) from the center of the circle
by the equation:
If the distance is less then the radius then the point is inside the circle.