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 Scud · Feb 20, 2013 at 06:04 PM · rotationvector3geometry

How to rotate Vector3 to EulerAngle?

I have a plane, defined by three points. For example:

  • O = Vector3.zero

  • A = Vector3(3,15,5)

  • B = Vector3(2,4,10)

I need to find fourth point var D : Vector3, knowing that point lies in the same plane, distance from A is 10 units and angle between my new point D and A from B (angle DBA) is 40 Euler degrees (in the direction of O).

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
0
Best Answer

Answer by robertbu · Feb 20, 2013 at 09:18 PM

Not really a Unity question, but here is an outline of one method:

  • From the triangle ABD, you have two sides and an angle, so you can get angle BAD.

  • Use A as an origin, create a vector AB normalized * 10

  • To get an axis, use A as an origin, and create an axis by AB cross AO

  • Use Angle Axis rotation with the calculated axis and calculated angle

  • Add back A to get point

Comment
Add comment · Show 4 · 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 Scud · Feb 21, 2013 at 04:38 PM 0
Share

I know all angles in my triangle, so I didn't need to take step 1. So I:

 var vectorAD = vectorAB;
 var rotationAxis = Vector3.Cross(vectorAB, vectorAO);
 // $$anonymous$$agic goes here
 VectorAD.ToAngleAxis(40, rotationAxis);
 var rayAD = new Ray (A, VectorAD);
 var D = rayAD.GetPoint(10);

Something like that? But of course, ToAngleAxis is not a member of UnityEngine.Vector3, so what should I do With VectorAD?

avatar image robertbu · Feb 21, 2013 at 05:40 PM 0
Share

Use a Quaternion for an angle/axis rotation. Here is what I was thinking sketched in code (totally untested and assumes you know the angle):

 var v3PointA : Vector3 = Vector3(3,15,5);
 var v3PointB : Vector3 = Vector3(2,4,10);
 var v3PointO : Vector3 = Vector3(0,0,0);
 
 // Need the normal to the plane.  Since
 //   v3PointO is at the origin, we can do
 var v3Axis = Vector3.Cross(v3PointA, v3PointB);
 
 var q = Quaternion.AngleAxis(angle, v3Axis);
 var v3VectorAD = (v3PointB - v3PointA).normalized * 10.0;
 v3VectorAD = q * V3VectorAD;
 
 var v3PointD = v3VectorAD + v3PointA;
avatar image Scud · Feb 21, 2013 at 05:53 PM 0
Share

Thank you! Just tested, it works. Summarize:

  • you can just multiply Quaternion by Vector3. So, to rotate Vector3 you need to multiply Quaternion with it.

  • To get Vector, perpendicular to plane with two Vectors, you need to multiply (Vector3.Cross) these two.

avatar image robertbu · Feb 21, 2013 at 07:05 PM 0
Share

Note: I believe in a Quaternion/vector multiplication the Quaternion must come first. I'm glad it worked. Sometimes stuff my head without testing takes a bit of fussing.

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

Use Unity's transform API to manipulate points? 0 Answers

How do you perform multiple rotations on the same object? - (in a single frame) 0 Answers

Rotating a direction Vector3 by Quaternion 2 Answers

How to achieve a rotation on "batch quads" ? 0 Answers

Rotate Vector3 array around a point 1 Answer


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