- Home /
Angle Of Ray
Look this image:
The is a 3D ray. Position A and B are Vector3. And I want the angle of the ray on position A.
Can you solve this complex problem.
Extra Inforamtions:
(Usually I am trying to create a portal)
Answer by robertbu · Apr 15, 2014 at 05:49 PM
There is not enough information here to be sure of the angle you want to calculate. That is to get an angle (signed or unsigned), you need a frame of reference. Let's assume that you are looking for the angle with reference to the XY plane. You could project the point onto the plane and then use Atan2() to get the angle:
var projectPoint = ProjectPointOnPlane(Vector3.forward, pointA, pointB);
var projectPoint = projectPoint - pointA;
var angle = Mathf.ATan2(projectPoint.y, projectPoint.x) * Mathf.Rad2Deg;
function ProjectPointOnPlane(planeNormal : Vector3 , planePoint : Vector3 , point : Vector3 ) : Vector3 {
planeNormal.Normalize();
var distance = -Vector3.Dot(planeNormal.normalized, (point - planePoint));
return point + planeNormal * distance;
}
Answer by koray1396 · Apr 15, 2014 at 05:49 PM
in your picture, it's 360 degrees.
here is the answer. http://docs.unity3d.com/Documentation/ScriptReference/index.html (hint: search for "angle")
@koray1396 - If what you are suggesting is Vector3.Angle(), it likely will not give him what he is looking for...first because it is unsigned, and second because the frame of reference would the two vectors, not the view he has in the drawing.