Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
1
Question by jeango · Sep 19, 2017 at 10:46 AM · vector3angledotproduct

Is Vector3.Dot faster than Vector3.Angle?

Hi, I'm currently reading stuff about the purpose of dot product, and from all I can tell, its main use is to determine wether two vectors are parallel or perpendicular, which is nice, but then on the other hand you also have Vector3.Angle returning the angle between two vectors, and it would be quite easy to determine from there if they are perpendicular too.

Also looking at the doc, to calculate the dot product, Unity uses the cosine of the angle, which feels a bit redundant.

So I'm wondering, if people actually use dot product for that purpose at all, is it for performance reasons? Or is there something more clever that you can do with dot products, that apparently no one seems keen to share in any tutorial video on dot products.

Comment
Add comment · Show 3
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 hexagonius · Sep 19, 2017 at 11:25 AM 0
Share

Don't know about the performance. But what you're describing about the dot product is just the case for two normalized vectors. If, however you match a vector against a normalized one, you get the amount of the first vector in the direction of the normalized one.
Like the amount of drift when using the dot product with the velocity and any side direction vector of the car.

avatar image Owen-Reynolds · Sep 19, 2017 at 12:59 PM 0
Share

The dot product is a standard mathematical thing. Formulas use it, people who know 3D trig use it. $$anonymous$$ath textbooks have the best explanations. But it seems like you don't have a strong trigonometry background (many very good game developers don't) and are confusing yourself.

If you really want to learn more math, you could review how cosine and arc-cosine work. Or just do what everyone else who hates trig does and use Angle.

avatar image orionsyndrome · Oct 28, 2018 at 03:51 AM 0
Share

Dot products or "scalar vector products" are used for a myriad of things: vector projections, interceptions, intersections, fast motion or proximity detectors, slope detectors, fast calculations of all sorts you'd otherwise do with trig. So yes, there is something more clever that you can do with dot products, but the topic is so vast I couldn't cover it in this comment alone. Cross products, or true vector products, are as much as important, and the two (along with the addition and subtraction) form the basis for the vector math.

If it helps, one could divide general geometry in three areas, and I'm talking exclusively from the game engineering perspective: 1) trigonometry, 2) vectors, 3) analytic geometry. Trigonometry, even really basic one, is usually quite enough when working with 2D, but mastering all of the fields can turn you into a beast in 3D.

Vectors are essentially very fast, computation-wise, and elegant enough if you know what you're doing. In my experience, they are also the easiest to visualize, however you have to keep in $$anonymous$$d that a single Vector3 can represent quite a few different things, a position, a direction, or a difference (or unpacked distance). I also use barycentric coordinates, which belong to affine geometry and you absolutely need dot products to even begin thinking stepping outside of the XYZ coordinate system.

For example, this is how you might compute an angle (in radians) between two given radial vectors (the assumption is that they share the same origin)

float calcAngle(Vector3 a, Vector3 b) { return $$anonymous$$athf.Atan2(Vector3.Cross(a, b).magnitude, Vector3.Dot(a, b)); }

Because arc length = radius * angle (s = r x theta) which is a definition of a radian. The method above returns the unit arc length when the vectors are normalized. For the general arc length, multiply the result by radius.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by balfire · Apr 25, 2018 at 07:32 PM

No. Unity does not use the cosine to calculate dot product. If you look around the internet you can find decompiled unity source files. There you can see that dot product is calculated as follows: dot(a,b) = a.x*b.x + a.y*b.y + a.z*b.z.

I myself use Dot when i need to find the cosine between two vectors. In fact, Angle is defined through the use of Dot.

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 Owen-Reynolds · Apr 25, 2018 at 10:32 PM 0
Share

The problem, if you want the angle, is there are two more steps. You have to normalize the vectors or know they already are. Then you have to think in reverse cosin. Ex: dot>0.707 ins$$anonymous$$d of angle<45.

When you ask if one thing is faster than the other, they have to be doing the same thing, and these aren't.

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

88 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Dot Product Help 0 Answers

Cull length of ProjectOnPlane vector3 to bound of normal in direction of travel? 0 Answers

Can't get correct angle between two world positions 1 Answer

Vector3.Angle only returns a static value, Help 0 Answers

Problem with Vector2/Vector3.Angle? 0 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