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
0
Question by nghien_rbc · Sep 15, 2020 at 08:49 AM · meshnormalperpendicular

Draw a perpendicular line from a vertex of the mesh

I try to draw a debug line from the vertex point P1 on the mesh follow the normal vector at this point. I calculated the normal vector by this code below while I have known the position of three points (P1, P2, P3)

 Vector3 side1 = P2 - P1;  
  Vector3 side2 = P3 - P1;
  Vector3 normal = Vector3.Cross(side1, side2);
  float perpLength = normal .magnitude;
  normal /= perpLength;  
  Debug.DrawLine(P1, P1 + (normal * 150), Color.green, 150, false);


The result below isn't my expectation. The line I have expected is the red line but it drew the green line in the opposite direction. I don't know how to control this situation to make the green line go outside the mesh. I'm really having trouble with math so I need some ideas to resolve that.

Thank you in advance. alt text

untitled.png (162.0 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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Bunny83 · Sep 15, 2020 at 09:25 AM

Unity works with a left-handed system. You have to use the left hand for almost all orientation relevant things ^^. You probably remember the right-hand rule for the cross product. However this only holds true in (the mathematical) right handed system.

Just think about it this way:

The cross product is always just

 c.x = a.y*b.z - a.z*b.y
 c.y = a.z*b.x - a.x*b.z
 c.z = a.x*b.y - a.y*b.x

No matter if you're in a left or right handed system. Imagine the X-Y plane is the same in both systems. In that case the z axis of the two systems point in opposite directions. If you pass in two x-y vectors as input for the cross product, the resulting vector will always look the same numerically. However since in one system the z-axis point in one way and in the other system it points in the opposite direction, it points physically in the opposite direction.


To turn a left handed system into a right handed system you would need to flip one axis. If you do you would get the result you expected, yet the numerical coordinates are all still the same. Though keep in mind that flipping space on one axis changes the orientation of everything. So triangles which had a clockwise winding from the outside would now have a counter clockwise winding as seen from the outside.

If you have trouble with linear algebra I can highly recommend the whole linear algebra series by 3b1b. Things relevant for this case would be chapter2 about basis vectors, chapter 9 about duality and chapter 13 about change of basis. Though if you have some time to spare I can recommend the whole series :)

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 nghien_rbc · Sep 16, 2020 at 06:53 AM 0
Share

Thanks for your very quality answer and your recommendations about the 3b1b channel :) I just find the solution to my question that to make the normal vector go outside the mesh, I check if P1 is the first point of the triple in triangle array or not. If it isn't the first point then change the only the sign from + to - on this line: Debug.DrawLine(P1, P1 + (normal * 150), Color.green, 150, false);

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

154 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

Related Questions

Is there a cheap way to flip a collider´s normals in real time? 0 Answers

Do we need to call RecalculateNormals() if normal vectors are assigned? 1 Answer

Generating Normals 1 Answer

How to get the normal of a line in relation to a specific point in 3D? 1 Answer

Drawing a cube by a new Mesh 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