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 fahruz · May 20 at 10:49 AM · geometryprojectionperspective

Position correspondence of a 3D point between a quadrilateral and a rectangle

I would like to find the coordinates of a 3D point P' on a rectangle matching the relative position of a point P on the plane formed by a quadrilateral as shown below (P isn't necessarily inside the quad). The four points of the quad Q1, Q2, Q3 and Q4 are mapped to the four points of the rectangle R1, R2, R3 and R4 respectively.

alt text

This problem is related to perspective transformations and the solutions I've found so far on the web are mostly very generic or for 2D transforms which don't handle points outside the quad (e.g. this one). I was wondering if there was a relatively simple solution to compute that point using Unity's functions.

point-correspondence.png (76.1 kB)
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

2 Replies

· Add your reply
  • Sort: 
avatar image
2

Answer by elenzil · May 20 at 06:53 PM

Here's an approach using barycentric coordinates. Here's the core routines, which convert a point and triangle to a triple of barycentric coordinates, and then the reverse. You can then use this on 4 triangles in your quad (eg, one triangle per vertex) and compute the four sets of barycentric coordinates from the source quad and then average the results in the destination quad.

Running example code is on GitHub here. It runs right in the editor. Drag stuff around w/ the editor.

And the core math:

 using UnityEngine;
 
 public static class QuadsAndPoint
 {
     // Given triangle ABC and a point,
     // return the barycentric coordinates of the point.
     static public float[] BaryFromTriangleAndPoint(Vector3 P, Vector3 A, Vector3 B, Vector3 C) {
         var ret = new float[3];
 
         ret[0] = ((B.y - C.y) * (P.x - C.x) + (C.x - B.x) * (P.y - C.y))
                  /
                  ((B.y - C.y) * (A.x - C.x) + (C.x - B.x) * (A.y - C.y));
         
         ret[1] = ((C.y - A.y) * (P.x - C.x) + (A.x - C.x) * (P.y - C.y))
                  /
                  ((B.y - C.y) * (A.x - C.x) + (C.x - B.x) * (A.y - C.y));
         ret[2] = 1 - ret[0] - ret[1];
 
         return ret;
     }
 
     // Inverse of BaryFromTriangleAndPoint().
     static public Vector3 PointFromTriangleAndBary(Vector3 A, Vector3 B, Vector3 C, float[] coeffs) {
         return A * coeffs[0] + B * coeffs[1] + C * coeffs[2];
     }
 }
 

Comment
Add comment · Show 6 · 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 fahruz · May 23 at 05:21 AM 0
Share

Reducing the problem to triangles is fine as long as all 4 points of the quad and the rectangle are considered for the interpolation and projection and the end result is the same.

avatar image elenzil fahruz · May 23 at 01:45 PM 0
Share

i'm thinking it's an under-constrained problem, with multiple answers that fit the criteria. off the top I'd say treat it as two problems of barycentric coordinates, eg points 1,2,3 and then points 3,4,1, and average the result. you could also consider all 4 triangles: 123 234 341 412, and average the results of that.

i'll see if I can work up a demo.

avatar image elenzil elenzil · May 23 at 06:35 PM 0
Share

edited the answer to include the core math for barycentric coords as well as a link to a runnning demo with quads.

Show more comments
avatar image
0

Answer by BurgessBH · May 26 at 11:16 AM

Thanks for sharing, I found a lot of interesting information here. A really good post, very thankful and helpful that you will write many more posts like this one.

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

138 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 avatar image

Related Questions

Can you create a camera perspective that doesn't change with viewing angle? 0 Answers

How to project a point on to a sphere? 1 Answer

Projetion Mapping on Unity 1 Answer

Vertical Perspective / Horizontal Orthographic 1 Answer

Change or Manipulate Camera Perspective View 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