So im trying to find a direction from an angle.
Here is what i got so far.
// Vertical
Vector3 dir1 = new Vector3(0.0f, Mathf.Sin(Mathf.Deg2Rad * vertAngle), Mathf.Cos(Mathf.Deg2Rad * vertAngle));
// Horizontal
Vector3 dir2 = new Vector3(-Mathf.Sin(Mathf.Deg2Rad * horzAngle), 0.0f, Mathf.Cos(Mathf.Deg2Rad * horzAngle));
This will give me either a horizontal or vertical direction.
However i want to combine these two directions into one.
So i have for example 45 deg up and 90 deg horizontally.
I tried adding and normalizing, but it dident really work.
Thx for showed interest!
To convert polar coordinates to a cartesian coordinates you just need to do this:
public static Vector3 GetDirection(float aAzimuth, float aAltitude)
{
aAzimuth *= Mathf.Deg2Rad;
aAltitude *= Mathf.Deg2Rad;
float c = Mathf.Cos(aAltitude);
return new Vector3(Mathf.Sin(aAzimuth) * c, Mathf.Sin(aAltitude), Mathf.Cos(aAzimuth) * c);
}
The Azimuth (heading) specifies the angle around they y axis [-180°, 180°]. The Altitude is the elevation angle which is in the range [-90°,90°].
However you can also simply use Unity’s Quaternion type like this:
var dir = Quaternion.Euler(azimuth, altitude, 0) * Vector3.forward;
fafase
August 1, 2015, 6:41pm
2
Are you looking for the cross product?
The result of the cross product of two vectors is another vector that is perpendicular to the plane on which the two vectors lie.
Based on the order of the parameter, the result is going up or down as shown on the picture.