Incognito
Incognito

Reputation: 39

How do I get the original number to calculate the sin and cos for a point on a circle?

I got this to move an object in a circle:

currentAngle += Time.deltaTime * angularSpeed;
offset = new Vector3(Mathf.Sin(currentAngle), 0, Mathf.Cos(currentAngle)) * circleRad;
transform.position = fixedPoint + offset;

Is there a way to get the original currentAngle (used to calculate a point) from a position on this circle, like backtrack the function?

Upvotes: 0

Views: 116

Answers (1)

JosephDaSilva
JosephDaSilva

Reputation: 1197

The atan2 function is what you are looking for.

In C# it is available as Math.Atan2, which takes double arguments. In addition, Unity (which you are probably using given the code sample in your question) has Mathf.Atan2 which takes float arguments.

Upvotes: 1

Related Questions