Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
1
Question by Hotdug · Jul 04, 2014 at 03:35 AM · 3dmathplanepoint

Find point in 3D plane

I have four points in a 3D space, example:

(0,0,1)
(1,0,1)
(1,0,2)
(0,0,2)

Then I have a 2D position on that square plane:

x = 0.5
y = 0.5

I need to find out the 3D space point of that position in the plane. In this example it's easy: (0.5,0,1.5) Because Y is zero. But imagine that Y was not zero (and not all the same), that the plane is leaning in some direction. How would I calculate the point in that case?

I imagine this should be a pretty easy thing to solve, but I can't figure it out. Please answer in programming terms and not in straight math terms.

Update with image: The gray plane (made out of two triangles) are the real one actually existing. I create a non-existing plane on top of this, the ABCD corners are exactly the same, however it doesn't slope. What I need to do is project a pixel (blue one in example) from the non-existing plane to the existing plane. It will be in the exact same location, except that it has gained a Y value from the sloping plane.

http://i.imgur.com/mgvi1ZL.png

What I've been able to work out so far on my own is which one of the two triangles to use in the gray plane and the normal of that triangle. I basically just need to figure out how I can project the pixel.

Comment
Add comment · Show 1
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 meat5000 ♦ · Jul 04, 2014 at 05:39 PM 0
Share

Saw you'd mentioned the word 'project'.

http://docs.unity3d.com/ScriptReference/Vector3.Project.html

3 Replies

· Add your reply
  • Sort: 
avatar image
-2
Best Answer

Answer by Hotdug · Jul 04, 2014 at 05:29 PM

Figured it out mostly thanks to http://gamedeveloperjourney.blogspot.com/2009/04/point-plane-collision-detection.html

Made me realize I had to verify the normal a bit closer, turns out my plane's grid was being rendered a little different than the actual coordinates for the verticles. No wonder this was so hard to get right! The pixel was projected correctly but rendered incorrectly.

Thanks for all the help guys, that blogspot entry can't take all the credits. You helped me too.

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 Bunny83 · Jul 04, 2014 at 07:50 PM 1
Share

Sorry, but that's not a valid answer since it doesn't answer the question at all.

avatar image
0

Answer by Benproductions1 · Jul 04, 2014 at 03:58 AM

OK, lets say we have a plane made of 3 points (4 points are not guaranteed to be planar), lets call them: A, B and C.

Now we want to calculate a point on the plane, given two of the points coordinates.

To find the other coordinate we can do a simple line-plane intersection test, where the line goes along the missing axis. Say we have X and Y, but want the Z coordinate, out line would be:

 (x, y, z) = (X, Y, 0) + t(0, 0, 1)

Lets call then:

 P = O + tD

Now that we have a line to intersect with, we just need to do the intersection test. The first step is to calculate the normal, N:

 N = AC × AB

t is then given by the formula:

 t = - (OA · N) / (N · D)

Since t is multiplied by a direction along the missing axis, it is equivalent to the value of your missing axis. The resulting point is therefore given by (using the same example):

 (X, Y, t)

Obviously you can adapt this to find any axis, but implementation is something you should do yourself.

This is really just standard line-plane intersection. If you don't understand any of the maths involved, I suggest you learn some linear algebra (Wikipedia), more specifically algebra involving vectors, lines and planes.

Comment
Add comment · Show 2 · 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 Hotdug · Jul 04, 2014 at 12:37 PM 0
Share

Is it possible to get that in a program$$anonymous$$g example? I don't really understand that otherwise. What confuses me the most is "now we want to calculate a point on the plane, given two of the points coordinates", surely I would need to use all three points of the plane to calculate the fourth point that I need? If the answer was put in program$$anonymous$$g terms (an example) maybe I would understand better what you mean.

avatar image Bunny83 · Jul 04, 2014 at 07:56 PM 0
Share

Since it's a very special case it doesn't actually need any fancy math. All you need is to cross multiply. From the prcture it's not clear if AB is the x or the z axis.

If "AB" is the x axis all you need is:

 //C#
 Vector3 Project(Vector3 aPos, Vector3 A, Vector3 DTop, Vector3 D)
 {
     float ratio =  (D.y - DTop.y) / (A.z - DTop.z);
     return new Vector3(aPos.x, (aPos.z - A.z)*ratio, aPos.z);
 }

If "AB" is the z axis all you need is:

 //C#
 Vector3 Project(Vector3 aPos, Vector3 A, Vector3 DTop, Vector3 D)
 {
     float ratio =  (D.y - DTop.y) / (A.x - DTop.x);
     return new Vector3(aPos.x, (aPos.x - A.x)*ratio, aPos.z);
 }

Of course if one or more of the A / D / DTop components are 0 the formula can be simplified a bit. Anyways we actually just need to calculating the slope. Since x and z stay the same we just need to calculate y based on the position in the direction of the slope. It's actually a simple 2D problem.

avatar image
0

Answer by robertbu · Jul 04, 2014 at 02:47 PM

Not completely sure of the criteria. I believe you want to project the point onto the plane:

 function ProjectPointOnPlane(planeNormal : Vector3 , planePoint : Vector3 , point : Vector3 ) : Vector3 {
     planeNormal.Normalize();
     var distance = -Vector3.Dot(planeNormal.normalized, (point - planePoint));
     return point + planeNormal * distance;
 }    

If that's not what you want, note that Unity's mathematical Plane class has a Raycast() function. Also you might want to take a look at the Math3d class in the Unity wiki.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

GUI Coordinate System 0 Answers

3D. How to get 1 pixel to equal 1 degree camera FOV 0 Answers

3d drawing based on movable planes? 0 Answers

Retrieve 2d primitives from 3d colliders 1 Answer

Pixel values of a plane (RectTransform)? 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