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
1
Question by gypaetus · Sep 04, 2014 at 06:24 AM · mathvector math

Unexpected results using Vector3.Angle()

Hi there,

I realize there must be a misunderstanding on my part in the maths behind how angles are calculated between vectors so I thought I'd ask here. Before I begin: this is a 2d problem:

I have an origin (8.9,2.3) and three points

  • (4,2)

  • (-11.5,0)

  • (4,1.6)

my goal is to find which points are struck first when sweeping a ray counterclockwise from the origin.

In the visual example provided, you can see that (4,2) should be struck first, followed by (4, 1.6) and finally (-11.5,0) - but I am getting counter intuitive results using Vector3.Angle to find the angle between these points

According to all sources I've used, (-11.5, 0) lies on a ray 2.9 degrees ccw from (4.2) and (4,1.6) lies on a ray 4.62 degrees ccw from 4.2 (using (8.9,2.3) as our origin)

  • WolframAlpha query:

    VectorAngle[{4-8.9,2-2.3},{4-8.9,1.6-2.3}] in degrees

4.627 deg

  • WolframAlpha query:

    VectorAngle[{4-8.9,2-2.3},{-11.5-8.9,0-2.3}] in degrees

2.929 deg

My question is this: Why?

Based on the visual example provided I would have expected different results.

visual example

halp.png (23.4 kB)
Comment
Add comment · Show 1
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 kacyesp · Sep 04, 2014 at 06:25 AM 0
Share

I upvoted this just because of the amount of effort you put into asking this.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by gypaetus · Sep 04, 2014 at 07:16 AM

Ah thank you!

Wouldn't you know it? Spend hours working on an issue only to find the answer 20 mins after posting the question! I've realize that the answer to my question was that I was using points rather than directions in my Vector3.cross call (to determine direction). Something that I entirely failed to mention because I didn't think the issue resided there!

 Vector3 cross = Vector3.Cross(direction1,direction2);
 int sign = 0;
 if(cross.z>sign){
     sign = 1;
 }
 else{
     sign = -1;
 }

Although this doesn't explain why wolfram alpha returns said results... Any Math people care to explain?

Comment
Add comment · 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

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

localPosition vs Position Subtraction as vector direction 1 Answer

Change direction of vector based on which way player is facing 1 Answer

Matrix Multiplication, Standard Deviant and More usefull methods 2 Answers

Minimap rotating nodes 1 Answer

Extending a vector? 4 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