Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 cmd_Unity · 6 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

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by cmd_Unity · yesterday

found a solution that does it for my purpose:

 private static Plane PlaneSrc, PlaneTrg;
 private static GameObject src_G0, trg_G0
 public static void Align3Point(GameObject go, Vector3 src0, Vector3 src1, Vector3 src2, Vector3 trg0, Vector3 trg1, Vector3 trg2, float drawDuration = 0f)
 {
     PlaneSrc = new Plane(src0, src1, src2);
     PlaneTrg = new Plane(trg0, trg1, trg2);
     
     src_G0 = new GameObject();
     src_G0.transform.parent = go.transform;
     src_G0.transform.position = src0;
     trg_G0 = new GameObject();
     trg_G0.transform.position = trg0;
 
      go.transform.rotation *= Quaternion.FromToRotation(PlaneSrc.normal, PlaneTrg.normal);
     go.transform.position += (trg_G0.transform.position - src_G0.transform.position);
 
     GameObject.Destroy(src_G0);
     GameObject.Destroy(trg_G0);
 }

Hope it helps other too.

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

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

LookRotation flipping 180 degrees through y axis 1 Answer

How do i get world position of collider if it inside multiple scaled gameobjects? 0 Answers

Adding an offset to an instantiated objects rotation 0 Answers

How does rotation.LookAt work? 1 Answer

How to rotate a cylinder on the mouse position ? 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