• 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 cmd_Unity · 3 days ago · rotate objectmatrix4x4

3 Point Align

Hello,

in an AR-Application I would like to align loaded scanned realworld meshes, with the current AR View of the real world.

The user should cklick 3 points on the scanned meshes (source), afterwards users should click 3 corresponding points in realworld (target). Therefore I have 2 sets, each with 3x Vector3 and want them to be used to calculate the transform to align the scanned meshes on realworld accordingly.

I tried several things but can not get right mathematic to get the desired reuslt:

-take each set of three points as a "plane", get those plane normals and use Quternion.LookRotation makes the "planes" parallel, but not in correct rotation (tried flipped or not flipped in various combinations)

 private void StartAlign(List<Vector3> src, List<Vector3> trg)
 {
         PlaneSrc = new Plane(src[0], src[1], src[2]);
         PlaneTrg = new Plane(trg[0], trg[1], trg[2]);
 
     Object_Scanned.transform.rotation = Quaternion.LookRotation(PlaneTrg.flipped.normal, PlaneSrc.normal);
 }

-get the matrix4x4 for each set, calculate and attach, but none of my mathematic tries brought up what i need (below just one example fpr matrix4x4):

 public void Align3Point(GameObject Objects_Scanned, GameObject to_target, List<Vector3> align_points, List<Vector3> target_points)
 {
         Matrix4x4 sourcePlane = MatrixFrom3Points(align_points[0], align_points[1], align_points[2]);
         Matrix4x4 targetPlane = MatrixFrom3Points(target_points[0], target_points[1], target_points[2]);
 
         alignPlane = Matrix4x4.Rotate(Quaternion.Lerp(sourcePlane.rotation, targetPlane.rotation, 360f));
 
         Objects_Scanned.transform.rotation = Quaternion.LookRotation(alignPlane.GetColumn(2), alignPlane.GetColumn(1));
 }
 
 public Matrix4x4 MatrixFrom3Points(Vector3 p0, Vector3 p1, Vector3 p2)
 {
         Vector3 x = p1 - p0;
         x.Normalize();
         Vector3 y = p2 - p0;
         Vector3 z = Vector3.Cross(x, y);
         z.Normalize();
         y = Vector3.Cross(z, x);
         y.Normalize();
 
         return new Matrix4x4(new Vector4(x.x, x.y, x.z, 0),
                              new Vector4(y.x, y.y, y.z, 0),
                              new Vector4(z.x, z.y, z.z, 0),
                              new Vector4(p0.x, p0.y, p0.z, 1));
 }




Can someone help me with the mathematic behind a 3 point align please?

Thank you so much

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

0 Replies

· Add your reply
  • Sort: 

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

137 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

Related Questions

Room rotation for door alignment 1 Answer

2D Rotation Angle Issue 1 Answer

How do I rotate using a negative angle value?,How to get the negative angle of an object? 2 Answers

[2D] Tranform.RotateAround flickers arrow between two positions when the mouse is close to the player 0 Answers

Rotate Cube with with mouse 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