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 UnderShad · Jul 09, 2020 at 07:55 PM · vector3planeprojection

Projecting a point on plane

Hi I am making a mesh builder which needs me to get all the vertices of a cube. I want to make a crooked cube with sides not at 90 degree but parallel to the ground as a parallelogram. I am already using project on plane where it is needed but. I want to find out the point on a plane which is not a game object but in code without using raycast.

It is in unity 3d not in 2d

I would be very thankful for your answer! alt text

unityquestion.png (33.2 kB)
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 unity_ek98vnTRplGj8Q · Jul 09, 2020 at 10:11 PM 0
Share

Have you tried Plane.Raycast?

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Insok · Jul 09, 2020 at 10:02 PM

Because you put effort in your question and made a drawing, I put effort in giving a decent answer.

This problem converts to a math problem of finding the intersection of a plane (given by a point and a normal vector), and a line (given by a direction vector and a point).

• Let's call the first point of the line (point to object) P1 (x1, y1, z1) and the second point P2 (x2, y2, z2). (P2 is another random point on the line, for example: P1 + direction vector towards plane).

• Let's call the known point on the plane P3 (x3, y3, z3) and the normal vector N (nx, ny, nz).

• Let's call the needed point P (x, y, z)


We can write the line equation in vector form as:
(P2-P1) . k + P1 (Where k is a random number)

1. We know that the needed point is on this line, for a certain value of k.

 x = k.(x2 - x1) + x1
 y = k.(y2 - y1) + y1
 z = k.(z2 - z1) + z1

We also know that the vector (P3-P) must be perpendicular to the normal vector N. (Since (P3-P) is a vector of the plane)

2. For perpendicular vectors applies that their dot product equals zero:

 (x3 - x).nx + (y3 - y).ny + (z3 - z)*nz = 0



Applying these 2 conditions, we get 4 equations with 4 variables: x, y, z and k.
When we solve these equations, we get:

 x = ( ((y3 - y2).ny + (z3 - z2).nz + nx.x3).x1 - x2.((y3 - y1).ny + (z3 - z1).nz + nx.x3) ) / ( (x1 - x2).nx + (y1 - y2).ny + (z1 - z2).nz )
 
 y = ( ((x3 - x2).nx + (z3 - z2).nz + ny.y3).y1 - y2.((x3 - x1).nx + (z3 - z1).nz + ny.y3) ) / ( (y1 - y2).ny + (x1 - x2).nx + (z1 - z2).nz )
 
 z = ( ((y3 - y2).ny + (x3 - x2).nx + nz.z3).z1 - z2.((y3 - y1).ny + (x3 - x1).nx + nz.z3) ) / ( (z1 - z2).nz + (y1 - y2).ny + (x1 - x2).nx )
 
 k = ( (x1 - x3).nx + (y1 - y3).ny + (z1 - z3).nz ) / ( (x1 - x2).nx + (y1 - y2).ny + (z1 - z2).nz )


You can either calculate x, y and z separately or calculate k and use it with the line equation.

I hope you understood somewhat what I tried to explain, best of luck!

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 UnderShad · Jul 10, 2020 at 10:56 PM 1
Share

$$anonymous$$agnificent, It works flawlessly I truly appreciate your help. Thanks for your immense effort. Please take a look what I have created with your help. And thanks again. Flushed Game object to the surface. With 1,2 known points and 5,6 calculated.

c1.png (80.3 kB)
avatar image Insok UnderShad · Jul 26, 2020 at 08:00 PM 0
Share

I'm glad to hear that it works, I calculated it but didn't have the chance to test it. The result looks great!

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

165 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 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

Projecting point into plane made by camera frame 0 Answers

Get point in plane where the normal crosses a GameObject in local space 2 Answers

Using the Horizontal Slider to Control a Plane's Y transform Variable 1 Answer

Rotate floor plane in-game via C# script 1 Answer

Resize Plane? 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