Comments and answers for "Find distance around a circle, from center point and another point"
http://answers.unity.com/questions/572670/find-distance-around-a-circle-from-center-point-an.html
The latest comments and answers for the question "Find distance around a circle, from center point and another point"Answer by shieldgenerator7
http://answers.unity.com/answers/1794712/view.html
Here's a modified version of @robertbu 's answer:
public static Vector2 travelAlongCircle(this Vector2 pos, Vector2 center, float distance)
{
Vector3 axis = Vector3.back;
Vector2 dir = pos - center;
float circumference = 2.0f * Mathf.PI * dir.magnitude;
float angle = distance / circumference * 360.0f;
dir = Quaternion.AngleAxis(angle, axis) * dir;
return dir + center;
}
You can call it like this:
Vector2 position = transform.position;
Vector2 center = Vector2.zero;
float distance = 10;
transform.position = position.travelAlongCircle(center, distance);
This version is handy because it is an extension method of the `Vector2` class.Sun, 06 Dec 2020 10:08:40 GMTshieldgenerator7Comment by Mythran on Mythran's answer
http://answers.unity.com/comments/1319449/view.html
Awsome!! Thank you very much!Mon, 27 Feb 2017 22:27:36 GMTMythranComment by Bobfan on Bobfan's answer
http://answers.unity.com/comments/572775/view.html
I'll try it out, and fix it if it doesn't work. Thanks.Sun, 10 Nov 2013 22:49:26 GMTBobfanAnswer by robertbu
http://answers.unity.com/answers/572675/view.html
There are an infinite number of circles that have a center and a point in common, so you need to specify one specific circle. The code below uses the axis (normal) to the circle. The polarity of the axis will determine which direction to move along the circle. It solves your problem by creating a vector between the center and the point. It then calculates the angle by using the fraction of the circumference the distance travels. An AngleAxis() rotation generates the point. The code is untested:
function FindPoint(center : Vector3, r : Vector3, dist : float, axis : Vector3) : Vector3 {
var v3 = r - center;
var circumference = 2.0 * Mathf.PI * v3.magnitude;
var angle = dist / circumference * 360.0;
v3 = Quaternion.AngleAxis(angle, axis) * v3;
return v3 + center;
}Sun, 10 Nov 2013 18:26:11 GMTrobertbu