Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to move n degrees from vector point A along the circumference of a circle? (image included)

enter image description here

A, B and Center are 2D vector points.

n is the length of the circle's circumference from A to B.

I want to get B.

I'm looking for a way to pop in A, Center, n and the circle's radius to pop out vector point B.

(I'm coding with C# in Unity using Mathf, but I don't need code as an answer, just some basic steps should help plenty, thanks)

like image 611
Sky Signor Avatar asked Oct 20 '22 03:10

Sky Signor


1 Answers

All angles are in radians. Your n is whats called the circles arc.

public Vector2 RotateByArc(Vector2 Center, Vector2 A, float arc)
{
    //calculate radius
    float radius = Vector2.Distance(Center, A);

    //calculate angle from arc
    float angle = arc / radius;

    Vector2 B = RotateByRadians(Center, A, angle);

    return B;
}

public Vector2 RotateByRadians(Vector2 Center, Vector2 A, float angle)
{
    //Move calculation to 0,0
    Vector2 v = A - Center;

    //rotate x and y
    float x = v.x * Mathf.Cos(angle) + v.y * Mathf.Sin(angle);
    float y = v.y * Mathf.Cos(angle) - v.x * Mathf.Sin(angle);

    //move back to center
    Vector2 B = new Vector2(x, y) + Center;

    return B;
}
like image 59
Imapler Avatar answered Oct 24 '22 00:10

Imapler