Question

What I want to do should be simple but it has been a while since I studied math.

Let's say I have Point and Arc classes as below. How can I check if the Point p lies on Arc a.

public class Point
{
    public double X;
    public double Y;
}

public class Arc
{
    public double Radius;
    public double StartAngle;
    public double EndAngle;

    // center of the arc
    public double Xc;
    public double Yc;
}


Point p = new Point() { X = 5, Y = 5 };
Arc a = new Arc()
{
    Radius = 5,
    StartAngle = 0,
    EndAngle = Math.PI/2,
    Xc = 0,
    Yc = 0
};
Was it helpful?

Solution

I came up with this answer which is posted here for future reference. I know it is not the most efficient method but it does the job.

// first check if the point is on a circle with the radius of the arc. 
// Next check if it is between the start and end angles of the arc.
public static bool IsPointOnArc(Point p, Arc a)
{
    if (p.Y * p.Y == a.Radius * a.Radius - p.X * p.X)
    {
        double t = Math.Acos(p.X / a.Radius);
        if (t >= a.StartAngle && t <= a.EndAngle)
        {
            return true;
        }
    }
    return false;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top