- Home /
Get new Point from Vector and Angle
Hi, I'm having some trigonometric problems. I need t find a new point (world coordinates) from two known vectors and the angle between them.
I already have alpha using the Vector2.Angle method. And beta = (360-alpha)/2
I need to find the point at the end of the red vector(the magnitude of this vector is known) given the two other gray vectors (also known), but I'm having some difficulties wrapping my head around it. Can anyone point me in the right direction?
Thanks
EDIT: I'm sorry, I should have said that the magnitude of the red vector is known.
If the shapes are not regular (Hexagon, Octogon, ...) or you don't know the exact geometry, and if you don't have more data, you won't be able to find the point at the end of the red line.
Follow the lines toward the centre you have marked but keep going and mark with a dotted line what comes out the other side. If youve done it right you can use these to find a unit vector of the red line but you can not find the magnitude.
Answer by Scribe · Jul 02, 2015 at 10:40 AM
This is one way of doing it:
public Vector3 point = Vector3.zero;
public Vector3 dir1 = Vector3.right;
public Vector3 dir2 = Vector3.up;
public float finalMagnitude = 1;
Vector3 answer;
void Update(){
Debug.DrawRay(point, dir1);
Debug.DrawRay(point, dir2);
answer = -(Vector3.Slerp(dir1, dir2, 0.5f).normalized*finalMagnitude);
Debug.DrawRay(point, answer, Color.green);
}
Basically the important line is answer =....
I use slerp with a value of 0.5 to get the vector half way between the two known ones, then i make it the correct magnitude and invert it so it flips to the other (obtuse angle) side.
It is also important to note that this equation must know your centre point, and must be given the vectors as directions from this point.
Scribe