Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 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 smslv · Mar 05, 2017 at 03:27 PM · normalsprocedural generationsplinebeziercurves

Correct normals on a cylindrical rail (hairy ball theorem)

According to the Hairy Ball theorem, it is not possible to get consistently oriented normals at any point on the curve.

What I want to achieve is a game object moving beneath a procedurally-generated rail (plain cylinder). To generate a tube I use a spline which consists of bezier curves. Thus, I need to get a correctly oriented normals at any point of the curve.

The code looks like this:

 Vector3 q2 = GetCurveTangent (...);
 
 Quaternion lookAt = Quaternion.LookRotation (q2);
 Vector3 normal = lookAt * Vector3.up;
 normal = Quaternion.AngleAxis (angle, q2) * normal;
 return point + normal * size;

Which generates the following normals:

alt text

On horizontal segments everything is correct, but on vertical ones, when tangent is oriented like Vector3.up, everything goes wrong.

The only advice I've received is to try and use the previous tangent instead of global up vector. But I can not get any good result out of it. What I tried to do is:

 Quaternion lookAt = Quaternion.LookRotation (q2, previousNormal);

but it is not clear what to place here:

 Vector3 normal = lookAt * ?

And any combination of tangent, normal and rotation gives me something like this:

alt text

So, the question is: how can one create a cylindrical rail and an object moving beneath it (using the normal facing strictly down the curve)? If curve is vertical, "down" is of course globally forward and so on.

y45kr.png (96.3 kB)
7ocva.png (187.5 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 unity_sgEEDSMkTLwwLw · Jul 24, 2021 at 11:28 PM

you can try something like this. I wrote this code according to my own purposes and it works on CatMull. You can also generate it while the curve points are been generating. First, take derivative of the spline that you use. Secondly apply for all generated point, cross product, in your case it will be Vector3.cross(Vector3.up, Derivative of any spline at time T (U)).

 public Vector3 FindSplineNormal(Vector3 P0, Vector3 P1, Vector3 P2, Vector3 P3, float U)
 {   //SplineNormals
     Vector3 NormalUp = Vector3.Cross(Vector3.up, (0.5f) * (Mathf.Pow(U, 2) * 3 * (-P0 + 3 * P1 - 3 * P2 + P3) + 2 * U * (2 * P0 - 5 * P1 + 4 * P2 - P3) + (-P0 + P2))).normalized;
     return NormalUp;
 }
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

Generating a Flat Mesh from Spline/Bezier Curve? 1 Answer

How best to make long pipes/cables in unity? 3 Answers

leantween ltspline control points setup 0 Answers

Spline off center using iTween 2 Answers

Circular curve using bezier formel 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