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

enter image description here

A, B and Center - vector vector points.

n is the circumference of a circle from A to B.

I want to get B.

I am looking for a way to put in A, Center, n and the radius of a circle to pull out the vector point B.

(I am coding C # in Unity using Mathf, but I don't need the code as an answer, just some basic steps should help a lot, thanks)

+4
source share
1 answer

All angles are in radians. Your n is what is called an arc of a circle.

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;
}
+2
source

All Articles