Angle Of Ray

Look this image:

25240-untitled.png

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)

in your picture, it’s 360 degrees.

here is the answer.

(hint: search for “angle”)

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;
}