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 Bobfan · Nov 15, 2013 at 10:31 PM · curvebezier

Find Direction of Bezier Curve

alt text

I've been googling around for a bit, but I haven't found anything useful. So my question is how do you get the two r points where the green line lies along the orange line?

hep.png (9.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
2
Best Answer

Answer by Bunny83 · Nov 16, 2013 at 01:50 AM

Well, you might have heard about the Derivative in math. Actually that's all you need ;)

If you take a look at the Bezier wiki page at the bottom of the cubic bezier curves section theres the first and second derivative equation. This equation gives you the tangent vector at the given "t" value. So if your control points are in worldspace, you get a worldspace vector

edit
I just re-read your question and it's not really clear what you actually want (and for what purpose).

The "helper points and lines" do not exist in the "combined" bezier equation. A bezier curve point can be calculated "manually" by doing a 3 step lerp like this:

 // C#
 public static Vector3 CalculateBezier(Vector3 P1, Vector3 P2, Vector3 P3, Vector3 P4, float t)
 {
     Vector3 A1 = Vector3.Lerp(P1,P2,t);
     Vector3 A2 = Vector3.Lerp(P2,P3,t);
     Vector3 A3 = Vector3.Lerp(P3,P4,t);
     
     Vector3 B1 = Vector3.Lerp(A1,A2,t);
     Vector3 B2 = Vector3.Lerp(A2,A3,t);
     
     return Vector3.Lerp(B1,B2,t);
 }

The points A1,A2,A3 are the corners of the orange lines and B1 and B2 are the corners of the green line. Since Vector3.Lerp is a function it's quite costy. That's why you usually simplify the equation.

 public static Vector3 CalculateBezier(Vector3 P1, Vector3 P2, Vector3 P3, Vector3 P4, float t)
 {
     t = Mathf.Clamp01(t);
     Vector3 A1 = P1 + (P2-P1) * t;
     Vector3 A2 = P2 + (P3-P2) * t;
     Vector3 A3 = P3 + (P4-P3) * t;
     
     Vector3 B1 = A1 + (A2-A1) * t;
     Vector3 B2 = A2 + (A3-A2) * t;
     
     return B1 + (B2-B1) * t;
 }

This is what "logically" happens inside Lerp, however the way i did it here it's actually worse than Vector3.Lerp ;) Since we work with Vectors all operations are also function calls.

Usually you use the combined equation for a cubic bezier curve which looks like this:

 // C#
 private static float cubeBezier(float P1, float P2, float P3, float P4, float t)
 {
     float rt = 1.0f-t;
     float rtt = rt * t;
     return rt*rt*rt*P1 + 3*rt*rtt*P2 + 3*rtt*t*P3 + t*t*t*P4;
 }

 private static Vector3 cubeBezier(Vector3 P1, Vector3 P2, Vector3 P3, Vector3 P4, float t)
 {
     t = Mathf.Clamp01(t);
     return new Vector3(
         cubeBezier(P1.x, P2.x, P3.x, P4.x, t),
         cubeBezier(P1.y, P2.y, P3.y, P4.y, t),
         cubeBezier(P1.z, P2.z, P3.z, P4.z, t),
     );
 }


This directly calculates the point on the curve. Usually no one is interested in the "helper lines".

I've simplified the equation for the last two helper points into this:

 public static float ControlPoint(float P1, float P2, float P3, float t)
 {
     return (P1+P3-2*P2)*t*t + (P2-P1)*2*t + P1;
 }
 public static Vector3 ControlPoint(Vector3 P1, Vector3 P2, Vector3 P3, float t)
 {
     t = Mathf.Clamp01(t);
     return new Vector3(
         ControlPoint(P1.x,P2.x,P3.x,t),
         ControlPoint(P1.y,P2.y,P3.y,t),
         ControlPoint(P1.z,P2.z,P3.z,t)
     );
 }

To get the first of the two points do this:

 ControlPoint(P1,P2,P3,t);

to get the second point do this:

 ControlPoint(P2,P3,P4,t);

Now there shouldn't be anything left ;)

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 Bobfan · Nov 16, 2013 at 02:29 PM 0
Share

Thanks for the all the extra info, and sorry for the confusion.

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

18 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

Related Questions

Bezier curve confusion on 2 points 1 Answer

Find Vector3 point exactly between two gameobjects with an offset perpendicular to the line connecting the two gameobjects 1 Answer

Filling the space between bezier curves with a texture, 1 Answer

Using Neodrop's Antares Bezier Curves 0 Answers

iTween for Dynamically Moving Objects around a Sphere 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