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 Damon117 · Dec 04, 2015 at 10:56 AM · rotationtransformmatrixalgorithm

Calculate the new coordinates of points after the plane of the points is transformed

Hi guys,

  1. I have 4 points(p0, p1, p2, p3) in the same plane; I know the coordinates all of these.

  2. Then the plane is translated and rotated,(not scaled); I know the new coordinates of p0, p1, p2; I don't know the coordinate of p3.

  3. How can I calculate the new coordinate of p3?

  4. What I current do, but not working:

  5. Init status:

    Vector3 initP0;
    Vector3 initNormal;
    Vector3 initP3;
    void beforeTransform(Vector3 p0, Vector3 p1, Vector3 p2, Vector3 p3)
    {
        initP0 = p0;
        initNormal = Vector3.Cross(p1-p0, p2-p0);
        initP3 = p3;
    }

  6. The plane is translated and rotated,(not scaled)

    Vector3 afterTransform(Vector3 p0, Vector3 p1, Vector3 p2)
    {
        Vector3 new_normal = Vector3.Cross(p1-p0, p2-p0);
        Vector3 translation = p0-initP0;
        Quaternion rotation = Quaternion.FromToRotation(normal, initNormal);
        Matrix4x4 matrix4x4 = Matrix4x4.TRS(translation, rotation, Vector3.one);
        return matrix4x4.MultiplyPoint3x4(initP3);
    }

Thanks in advance.

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

Answer by Bunny83 · Dec 04, 2015 at 10:11 PM

Saving just the normal of the plane isn't enough. The normal and a point defines a plane, but such a plane doesn't have an orientation around the normal.

The easiest way is to save the position of the 4th point in relation to the other points.

One way is to express the point as a 2d vector within the plane. As unit vectors you would use the vectors p0->p1 and p0->p2.

Something like that:

 public Vector2 pos;

 void beforeTransform(Vector3 p0, Vector3 p1, Vector3 p2, Vector3 p3)
 {
     Vector3 a = (p1 - p0);
     Vector3 b = (p2 - p0);
     Vector3 c = (p3 - p0);
     pos = new Vector2(Vector3.Dot(a, c) / a.sqrMagnitude, Vector3.Dot(b, c) / b.sqrMagnitude);
 }

 Vector3 afterTransform(Vector3 p0, Vector3 p1, Vector3 p2)
 {
     Vector3 a = (p1 - p0);
     Vector3 b = (p2 - p0);
     return p0 + a * pos.x + b * pos.y;
 }

Another way would be to calculate the barycentric coordinates of your 4th point in relation to the triangle that p0, p1, p2 define. To get new position you just need to use the barycentric coordinates with the new points.

In both cases the new point will also scale and even skew with the new points.

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 Damon117 · Dec 05, 2015 at 10:59 AM 0
Share

Thanks Bunny. The "barycentric coordinates" works.
Paste codes in case someone runs into the same problem.

 Vector3 barycentric;
 
 void beforeTransform(Vector3 p0, Vector3 p1, Vector3 p2, Vector3 p3)
  {
      barycentric = GetBarycentric(p0,p1,p2,p3);
  }
 
 Vector3 afterTransform(Vector3 p0, Vector3 p1, Vector3 p2)
  {
      return barycentric.x * p0 + barycentric.y * p1 + barycentric.z * p2;
  }
 
 Vector3 GetBarycentric(Vector3 aV1, Vector3 aV2, Vector3 aV3, Vector3 aP)
             {
                 Vector3 a = aV2 - aV3, b = aV1 - aV3, c = aP - aV3;
                 float aLen = a.x * a.x + a.y * a.y + a.z * a.z;
                 float bLen = b.x * b.x + b.y * b.y + b.z * b.z;
                 float ab = a.x * b.x + a.y * b.y + a.z * b.z;
                 float ca = a.x * c.x + a.y * c.y + a.z * c.z;
                 float cb = b.x * c.x + b.y * c.y + b.z * c.z;
                 float d = aLen * bLen - ab * ab;
                 Vector3 B = new Vector3((aLen * cb - ab * ca), (bLen * ca - ab * cb)) /d;        
                 B.z = 1 - B.x - B.y;
                 return B;
             }

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

i am using a code to make my cube walk with character controller ,but when i play the cube spins. 0 Answers

Rotation problem 0 Answers

transform rotation inaccuracy 0 Answers

Creating a camera controller for isometric view - Positioning the camera 1 Answer

How can I make an object transform to given position and rotation 2 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