Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Stradigos · Jan 03, 2013 at 07:04 AM · c#mathvector

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.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

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.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Stradigos · Jan 04, 2013 at 04:58 AM 0
Share

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

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

10 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges