- Home /

# Converting an Azimuthal Coordinate to Vector3D?

Hey guys,

I'm following this really great tutorial on steering behaviors and converting it over from AS 3.0 to C# for Unity (obviously). All is going well. I've managed to get seek/flee/arrive working, but there's one line for wander I'm having issues with.

Apparently there's an overload for Vector3 in AS 3.0 that builds a vector from its azimuthal coordinates (eyes glazing over).

```
public Vector3D(double alpha,
double delta)
Simple constructor. Build a vector from its azimuthal coordinates
Parameters:
alpha - azimuth (α) around Z (0 is +X, π/2 is +Y, π is -X and 3π/2 is -Y)
delta - elevation (δ) above (XY) plane, from -π/2 to +π/2
```

What's the trick to converting "displacement = new Vector3D(0, -1);" in AS 3.0 to a Vector3D? Thanks in advance... you guys are generally awesome at helping out.

**Answer** by StephanK
·
Jan 03, 2013 at 08:58 AM

You will have to write your own function/constructor that does the conversion for you. You can use this: http://en.wikipedia.org/wiki/Azimuth as a reference. The basic idea is that the vector is described using a horizontal and vertical angle. I guess in your case (wander behaviour) the vector should describe a direction, not a point, so you can probably use some Quaternion math to get the result you want.

If I understood this correctly something like this should work for you:

```
using UnityEngine;
using System.Collections;
public class QuaternionTest : MonoBehaviour {
// Use this for initialization
void Start () {
float az = 90;
float el = 0;
Debug.Log(AzimuthToVector3(az, el));
}
Vector3 AzimuthToVector3 (float az, float el)
{
Vector3 vec = Vector3.forward;
vec = Quaternion.Euler(-el,az,0) * vec;
return vec;
}
}
```

Note that the Y and Z axes seem to be switched between Unity and Flash and as phodges mentioned your tutorial uses radians rather than degrees, so you will have to convert the values of az and el.

Thanks! Funnily enough, I saw that Unity had a Random.OnUnitSphere method and went with that since I'd like to use it for 3D. Your function would basically be Random.OnUnitCirle, if one existed. I'll keep it for the future though!

### Your answer

### Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.

### Follow this Question

### Related Questions

Point Line Plane Body 0 Answers

Given a vector, how do i generate a random perpendicular vector? 5 Answers

Multiple Cars not working 1 Answer

Vector Math Question 2 Answers

Distribute terrain in zones 3 Answers