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 ShayneK · Jan 19, 2017 at 09:52 PM · rotationvector3quaternionscoordinate-system

How to determine one point (Vector3) based on 7 other points (Vector3's) with 2 coordinate systems?

I have a 3d model of a room and I know the coordinates (Vector3's) of 4 points in that room, 3 reference points and 1 point we will call pointOfInterest.

In unity I am able to get the coordinates (Vector3's) of those 3 reference points but the orientation/rotation is different to that of the 3d model. The scale is fine. What I am trying to do is find where the pointOfInterest would be in the unity coordinate system based on the 3 reference points in unity relating to the 3 reference points in the 3d model and knowing where the pointOfInterest is in relation to the 3 reference points in the 3d model - direction and distance.

I have looked into using Vector3.RotateTowards(), Vector3.Angle() and a little bit into Quaternions but I can't seem to grasp the exact methods I need to use to solve this. A point in the right direction would be great and some example code (C#) would be amazing!

Key things to note:

  • Goal is to find the Vector3 of pointOfInterest within unity
  • Reference points in the 3d model map to the reference points in unity
    • ReferencePointA in 3d model is equal to ReferencePointA in unity
    • ReferencePointB in 3d model is equal to ReferencePointB in unity
    • ReferencePointC in 3d model is equal to ReferencePointC in unity
  • In the 3d model we can figure out distances and directions between each reference point and pointOfInterest

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 ShayneK · Jan 25, 2017 at 07:45 PM

This has been solved so I am putting my solution here in case anyone else runs into the same problem.

I had to put ReferencePointA -> ReferencePointB as a line/direction along the Z-Axis and ReferencePointB -> ReferencePointC as a line/direction along the X-Axis. Then I calculated how far down each line each point was and then used the distance and direction to calculate where the point was. Here is the code in case anyone wanted it:

 private Vector3 Convert(Vector3 vecToConvert)
     {
         Vector3 vecToReturn = new Vector3();
 
         //Find how far down the X axis the point is from refPointBModel -> refPointCModel. Gives refXDis.
         float modelBX = refPointBModel.x;
         float modelCX = refPointCModel.x;
         float refXDisBC = modelCX - modelBX;
 
         float refXDis;
         float transX = vecToConvert.x;
 
         //This determines which way the x-axis goes from B -> C
         if (refXDisBC > 0)
             refXDis = transX - modelBX;
         else
             refXDis = revitBX - transX;
 
         //Find how far down the Z axis the point is from refPointBModel -> refPointAModel. Gives refZDis.
         float transZ = vecToConvert.z;
         float modelBZ = refPointBModel.z;
         float refZDis = transZ - modelBZ;
 
         //Get the X coordinate based on how far between refPointBLocal -> refPointCLocal refXDis is. Gives xPoint.
         //Get direction of refPointBLocal -> refPointCLocal.
         Vector3 xDirection = (refPointCLocal - refPointBLocal).normalized;
         //Use distance and get X coordinate.
         Vector3 newXSpot = refPointBLocal + (xDirection * refXDis);
 
         //Get the Z coordinate based on how for between refPointBLocal -> refPointALocal refZDis is. Gives zPoint.
         //Get direction of refPointBLocal -> refPointALocal.
         Vector3 zDirection = (refPointALocal - refPointBLocal).normalized;
         //Use distance and get Z coordinate.
         Vector3 newZSpot = refPointBLocal + (zDirection * refZDis);
 
         //Calculate Y Axis.
         float transY = vecToConvert.y;
         float modelBY = refPointBModel.y;
         float refYDis = transY - modelBY;
         float newYCoordinate = refPointBLocal.y + transY;
         
         Vector3 result = (newXSpot + newZSpot) - refPointBLocal;
         vecToReturn = new Vector3(result.x, newYCoordinate, result.z);
 
         return vecToReturn;
     }
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

107 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

Related Questions

Move ball player relative to camera rotation 1 Answer

How do you rotate a rigidbody while maintaining world-coordinate velocity? 0 Answers

Get object's rotation around axis defined by vector 2 Answers

Smooth rotate between changing rotations (already using Lerp, problems arise) 0 Answers

Rotating 3d person character 0 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