philm
philm

Reputation: 885

Looking for algorithm that will determine if a point is to the left/right of an arc

I am currently in need of locating an algorithm that will determine if a point is to the right or left of an arc. This is an extension of the following algorithm to include arcs:

 // isLeft(): tests if a point is Left|On|Right of an infinite line.
//    Input:  three points P0, P1, and P2
//    Return: >0 for P2 left of the line through P0 and P1
//            =0 for P2  on the line
//            <0 for P2  right of the line
//    See: Algorithm 1 "Area of Triangles and Polygons"
inline int
isLeft( Point P0, Point P1, Point P2 )
{
    return ( (P1.x - P0.x) * (P2.y - P0.y)
            - (P2.x -  P0.x) * (P1.y - P0.y) );
}
//===================================================================

This code was retrieved from the site: http://geomalgorithms.com/a03-_inclusion.html

And this is used for the winding number algorithm. My goal is to expand this algorithm to include arcs and not just lines.

It is not quite like this post here: How to determine whether a point (X,Y) is contained within an arc section of a circle (i.e. a Pie slice)?

In the post mentioned, the author is trying to determine if the point lies within the central angle of the arc. Mine is slightly different in the sense that a point can be beyond the radius but the arc still contains the point in question.

I created a picture of what I am attempting to describe. Please note that I am not a drawer in any way. Anyways, the arc in question is green. I created two parallel lines that intersect the arc at the start and end nodes respectively. These lines are colored red. Please forgive my drawing skills. Even though the red lines in the drawing may appear to not be parallel, they are suppose to be parallel. The drawing is just for reference. I am defining in this post that the lines are parallel. This post here supersedes whatever is in the drawing. This means that even if the drawing does not indicate that the lines are parallel to each other, they are in fact suppose to be parallel to each other since I have stated this in the post. I need assistance in coming up with an algorithm that will determine if a point lies within the blue area. Note that the red lines can extend infinitely. For the sake of discussion, I ended the lines at an arbitrary point to color in the blue area.

If the point lies within the blue area, I consider this as the arc containing the point. As a side note, I am coding this algorithm in C++ (hence the c++ tag)

The type of arc I'm talking about is a circle's arc with a start and end node, an arc angle, and a circle center point and radius.

Edit:

The two answers by Yves and MBo contain better pictures at what I am attempting to explain. Please refer to these pictures. MBo contains the better of the pictures.

As Yves has described, I am attempting to test if a point lies within a semi infinite slab delimited by the arc and two parallel lines. These lines intersect the start and end node. Refer to MBo drawing for a clearer picture. Yves first drawing is also a clear picture. I am testing if the point lies in the shaded region.

I am using the terms left and right as a perspective. I apologize that I did not clearly explain this the first time I created the post. Imagine that you are traveling on this arc in a counter clock wise motion. The first node would be the right most node and the end node would be the left most node. From the perspective of the traveler, a point that is contained by this arc (or the semi-infinite slab) would be to the left of the arc. Any points to the right would be outside of the arc.

Upvotes: 0

Views: 803

Answers (2)

user1196549
user1196549

Reputation:

Hint:

If your final goal is to implement the widing number algorithm, what you are asking is to test if the point lies inside a semi-infinite slab delimited by two parallel lines (say horizontal, such that Yb < Y < Ye) and the arc.

The equation of the circle reads (X - Xc)² + (Y - Yc)² = R², from which you draw the condition X < Xc + √(R²-(Y - Yc)²). For convenience, you can split all arcs so that they only meet an horizontal once.

enter image description here

In other configurations, you will have to consider the intersections on the other side, X < Xc - √(R²-(Y - Yc)²), but I leave you the complete discussion. enter image description here

Upvotes: 3

MBo
MBo

Reputation: 80177

Let you have arc center C, radius R, ends A and B.

If I understand your wishes correctly:

If point P and center C lies in the same semi-plane against AB line:
check whether projection of point P onto AB line lies in the limits of AB segment
else (if point P and center C are in different semi-planes):
check that distance from P to C does not exceed R

if Sign(CrossProduct(P-A,B-A))  =   Sign(CrossProduct(C-A,B-A))
    Result =  DotProduct(P-A, B-A) / DotProduct(B-A, B-A)  in range 0..1
else
    Result =  DotProduct(P-C, P-C) <= R^2

For example, sign conditions is true for points K and H and result is true for H. Sign condition is false for I and J, result is true for point J

enter image description here

Upvotes: 2

Related Questions