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
0
Question by Dvergar · Mar 04, 2018 at 03:08 PM · rotationquaternionplanenormalsalign

Align a plane with 3 normal

I have a region with 3 normals and now I want to align a plane in this region. The two shown in the picture and one perpendicular facing up (created with pca, but that doesent matter) alt text

 GameObject Gplane = GameObject.CreatePrimitive(PrimitiveType.Plane);
 Transform t = Gplane.transform;
 t.position = segment.middle;
 t.localScale = new Vector3((2*segment.dist_pc1)/10, 0, (2*segment.dist_pc2)/10);
 t.rotation = Quaternion.FromToRotation(Vector3.right, segment.middle - segment.pc1);
 t.rotation *= Quaternion.FromToRotation(Vector3.forward, segment.middle - segment.pc2);
 t.rotation *= Quaternion.FromToRotation(Vector3.up, segment.normal)

I create a newgameobject from primitivetype plane. get transform and set its position and scale (segment is a object which contains all information about this region). Then I want to align the plane with the three normal, each rotation works fine and aligns the plane with the axis, but multiplied its messed up. alt text As you can see the plane is kind of between the two normals (blue and red, which you can hardly see but i am sure you can image) Any advice in what i am doing wrong is appreciated since i am not too familiar with quaternions and rotations. Thanks in advance.

region-with-3-normal-pls-plane.png (147.3 kB)
region-with-3-normal.png (193.1 kB)
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

Answer by Dvergar · Mar 19, 2018 at 02:44 PM

After digging some more I found a working solution.

Instead of calclating the angle one can set the right, forward und up vector of any transform. This will do rotation automatically

 t.right = segment.pc1

But since the vector is rotated by itself (Vector3, two defining position in space, the third may let the vector rotate around itself) the plane may be rotated around the this axis (and t.forward is not alinged with segment.pc2) To fix this i calculated the angle between t.forward and segment.pc2

 float angle = Vector3.Angle(t.forward, segment.pc2);
 t.RotateAround(segment.middle, t.right, - angle);

RotateAround allowed me to keep the axis that was already set and correct.

I tried to align a plane with two vector3 that is facing in the corresponding directions of the two vectors. Maybe this can help anybyody.

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

158 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 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

Rotate around local Y axis using Joystick Vector3 0 Answers

Smooth card rotation with Quaternion not doing anything 1 Answer

align object with collision normal then look at an object on one axis 0 Answers

Car weirdly flips 180 degrees while rotating to ground normal 0 Answers

Rotating an Object (To Face Another Object) Only on X and Y Axis 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