- Home /
Find two points which are on 120 degrees from a third point.
I drew this graphic:
If you check better all 4 points including the center of the circle are on Z = z1. I know the center of the circle which is (x1, y1, z1). I also know the top point which is (x1, y1 + r, z1). And I know that the other two points are on angle of 120 degrees. How can I find x2, y2, x3 and y3 using some useful functions from Unity.
Note: I know pytagorean theroem. No need to mention it.
I could possibly make some math with lines on a plane and where they intersect but that seems rather complex.
You can rotate the point (x1, y1+r,z1) around the center by 120/240 degrees to get the other two points (quaternion * vector3).
Edit (to be more specific): - move the the center (and with it the first) point to (0,0,0) - rotate the first point by 120degrees (with quaternion * vector3) for the second - and then again for the third - move center (and all other points) back to original position.
Answer by Garazbolg · Oct 14, 2015 at 08:48 AM
Or you could do it with trigonometry :
x2 = x1 + cos(30°) * r;
x3 = x1 - cos(30°) * r;
y2 = y3 = y1 - sin(30°) * r;
but to make it even simpler 'sin(30°)' is equal to 1/2
so y2 = y3 = y1 - r/2;
In Unity :
float cos30_R = Mathf.Cos(30 * Mathf.Deg2Rad) * r;
x2 = x1 + cos30_R;
x3 = x1 - cos30_R;
y2 = y3 = y1 - r/2;
It should use less ressources then your method.
Answer by 0potable · Oct 06, 2015 at 09:18 AM
One quick dirty way on top of my head : use a Transform as a helper.
1) transform.position = circleCenter
2) transform.LookAt(topPoint, Vector3.up)
3) transform.Rotate(Vector3.up * 120f)
4) transform.TransformPoint(Vector3.forward * radius) <<
5) Repeat step 3 & 4 for the last point
Note that the Vector3.up of the second step need to represent the "up" direction of the circle.
Answer by spinnerbox · Oct 14, 2015 at 07:32 AM
This function works perfectly:
function RotatePointAroundPivot(point: Vector3, pivot: Vector3, angles: Vector3): Vector3 {
var dir: Vector3 = point - pivot; // get point direction relative to pivot
dir = Quaternion.Euler(angles) * dir; // rotate it
point = dir + pivot; // calculate rotated point
return point; // return it
}
From this question: http://answers.unity3d.com/questions/532297/rotate-a-vector-around-a-certain-point.html
Your answer
Follow this Question
Related Questions
How To Calcutale New Position and Angle On The Line Objects 2 Answers
Clamp rotation of sprite? 0 Answers
How to find acute and obtuse angle between 2 points 1 Answer
Shade Based on Normal Map World Position Angle (Updated) 1 Answer
how can i determine the angle of the face of an object relative to the world? 0 Answers