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 DMeville · Jan 02, 2015 at 07:24 AM · vectornormalsplinetangent

Generate cylindrical mesh around 3D Catmull-rom spline

The spline is curve is defined by 4 points: p0,p1,p2,p3 and drawn between p1 and p2 with a for loop, looping through the number of segments I want. The point on the curve at time t can is being found with this function:

 public Vector3 GetSpline(Vector3 p0, Vector3 p1, Vector3 p2, Vector3 p3, float t) {
         Vector3 ret = new Vector3();
         float t2 = t * t;
         float t3 = t * t * t;
 
         ret.x = 0.5f * ((2.0f * p1.x) +
         (-p0.x + p2.x) * t +
         (2.0f * p0.x - 5.0f * p1.x + 4 * p2.x - p3.x) * t2 +
         (-p0.x + 3.0f * p1.x - 3.0f * p2.x + p3.x) * t3);
 
         ret.y = 0.5f * ((2.0f * p1.y) +
         (-p0.y + p2.y) * t +
         (2.0f * p0.y - 5.0f * p1.y + 4 * p2.y - p3.y) * t2 +
         (-p0.y + 3.0f * p1.y - 3.0f * p2.y + p3.y) * t3);
 
         ret.z = 0.5f * ((2.0f * p1.z) +
         (-p0.z + p2.z) * t +
         (2.0f * p0.z - 5.0f * p1.z + 4 * p2.z - p3.z) * t2 +
         (-p0.z + 3.0f * p1.z - 3.0f * p2.z + p3.z) * t3);
 
         return ret;
     }


I think I can figure out all the mesh generation stuff but I just can't figure out how to get a "normal" vector from the "direction vector" (segmentEnd-segmentStart). I feel like this is stupidly simple.. but my 3d maths isn't that great.

Any idea? Thanks!

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 DMeville · Jan 02, 2015 at 08:02 AM 0
Share

Ins$$anonymous$$d of doing it with math I aligned an empty gameobject to the setmentsStart, and used go.transform.rotation = Quaternion.LookRotation(dirVec); Then used go.transform.right and go.transform.up to offset the mesh extrusion. It works, but it doesn't seem like a clean way to do it

1 Reply

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

Answer by MakeCodeNow · Jan 03, 2015 at 06:27 AM

Take your normalized direction/tangent vector and cross product it with any non-parallel vector (like global up). Normalize the result to get one of the spline local axes. Then, cross that axis with the original normalized direction/tangent vector and you have the other axis. Congratulations, you now have the three axes of a spline point local matrix.

Lots more info on Wikipedia

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 DMeville · Jan 03, 2015 at 06:30 AM 0
Share

Wow man. You rock, I always forget about the cross product. This looks like exactly what I was looking for :)

Just tried it, works like a charm, and much neater than my hacky solution. Cheers mate.

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

exact vector reflection along collision normal vector 1 Answer

Custom gravity based on normal vector and rigidbody.addForce 2 Answers

Problem importing baked normal map from 3ds max 1 Answer

Tangent Space Normal Map to World Space Normal Vector in C# Script 0 Answers

Get normal direction to use as sign 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