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 /
avatar image
0
Question by ptjal · May 03, 2016 at 09:37 AM · quaternionprecisionvector3.anglevector3.project

spherical projection of points to plane, precision error?

Working on a spherical to planar mapping and have run into what seems like a precision error and am not sure how to address. To start with, I'm considering two points on the sphere. I want to get a planar vector that represents the difference of these two points on the planar projection. To setup the projection, I assume the first point is the center of the projection and I create a rotation to bring this point onto the xz plane. I then project the second point onto the plane associated w/ the center point, then rotate this projection via the computed rotation. It does seem to work for the most part, but my accuracy seems to be only about 3 decimal places. If my math is correct, I should be able to compute this projection from p1 to p2 and from p2 to p1 and get the same answer but in reverse. Code and results are below. Anyone see what I'm doing wrong or see ways of improving the accuracy?

      static Quaternion ComputeRotation(Vector3 vector) {
         // compute xy angle/rotation
         var xyProjection = new Vector3(vector.x, vector.y, 0);
         var xyAngle = Vector3.Angle(xyProjection, Vector3.up);
         var xyRot = Quaternion.Euler(0, 0, (vector.x>0.0f) ? xyAngle : -xyAngle);
         // compute yz angle/rotation
         var yzProjection = xyRot * vector;
         var yzAngle = Vector3.Angle(yzProjection, Vector3.up);
         var yzRot = Quaternion.Euler((vector.z>0.0f) ? -yzAngle : yzAngle, 0, 0);
         return yzRot * xyRot;
     }

     public static Vector3 ProjectPoint(Vector3 centerVector, Vector3 point, float scale=1.0f) {
         var rotation = ComputeRotation(centerVector);
         var projection = rotation * Vector3.ProjectOnPlane(point*scale, centerVector.normalized);
         return projection;
     }

 [TestFixture]
 public class TestProjection {
     [Test]
     public void TestProjectPoint() {
         var p1 = new Vector3(0.195f, 0.981f, 0.0f);
         var p2 = new Vector3(0.377f, 0.911f, -0.167f);
         var pp12 = Projection.ProjectPoint(p1, p2, 1.0f);
         var pp21 = Projection.ProjectPoint(p2, p1, 1.0f);
         Debug.Log("pp12: " + pp12.ToString("F4") + " pp21: " + pp21.ToString("F4"));
         Assert.True(Geometry.CloseEnough(pp12, -pp21));
     }
 }

pp12: (0.1922, 0.0000, -0.1670) pp21: (-0.1949, 0.0000, 0.1638) UnityEngine.Debug:Log(Object) TestProjection:TestProjectPoint() (at Assets/Editor/Tests/TestProjection.cs:15)

Comment
Add comment · Show 2
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 Piflik · May 03, 2016 at 01:38 PM 0
Share

Is there a specific reason for the projection ins$$anonymous$$d of trigonometry?

https://en.wikipedia.org/wiki/Great-circle_distance

avatar image ptjal Piflik · May 03, 2016 at 03:17 PM 0
Share

Yep. I'm actually trying to compute a planar projection of a larger surface of the sphere. I'm creating a grid of equal area quads and then projecting a set of those quads onto a plane, given a center point. I could probably change to use great circle distances (I had thought about it) and then use that as the magnitude of my directional vector, but the directional vector using the rotation I think would still have the precision issue w/ rotation. The current magnitude precision w/ the same data points looks like:

 pp12.mag: 0.254583 pp21.mag: 0.254640
 UnityEngine.Debug:Log(Object)

If there is a better way of setting up a projection using trig, I'd love to hear about it. $$anonymous$$y trig is really rusty. Thanks!

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Quaternion.ToAngleAxis is Unprecise? 1 Answer

Quaternion.LookRotation precision error 1 Answer

Weird rotation precision 2 Answers

Convert Quaternion to vector3 and help on Return Angle Between Two GameObject using Vector3.Angle 1 Answer

Question about angles. 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