• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Getting cartesian values from Bezier curve question
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Getting cartesian values from Bezier curve question


  • Subject: Re: Getting cartesian values from Bezier curve question
  • From: John Randolph <email@hidden>
  • Date: Tue, 15 Jun 2004 20:48:23 -0700

The problem here is that not all Bezier cubic splines have exactly one value for Y for a given value of X. The best you can get is the value of y for a given value of t.

If you want to solve for (x,y) = f(t), I used this code one upon a time:

float bezierInterpolation(float t, float a, float b, float c, float d)
{
float
tSquared, tCubed, threeA, threeB, threeC;

tSquared = t * t;
tCubed = tSquared * t;
threeA = a * 3.0;
threeB = b * 3.0;
threeC = c * 3.0;

return
(a + (-threeA + t * (threeA - a * t)) * t
+ (threeB + t * (-threeB * 2.0 + threeB * t)) * t
+ (threeC - threeC * t) * tSquared
+ d * tCubed);
}

NSPoint bezierInterpolationPoint(float t, NSPoint *points)
{
return
NSMakePoint( bezierInterpolation(t, points[0].x, points[1].x, points[2].x, points[3].x),
bezierInterpolation(t, points[0].y, points[1].y, points[2].y, points[3].y));
}

Just to make it understandable to myself, I wrote the first function to work in a single dimension, and built the second one from that.

Now, if you ensure that x is equal to t, (which you can if you space the X values of the control points correctly) this should get you what you need.

HTH,

-jcr


On Jun 14, 2004, at 4:05 PM, dan donaldson wrote:

Hello Wise Ones

I am considering adding a control to allow users to use a Bezier Path to edit a set of values that change over time. The essentials are a timeline with values determined by keyframes which will be represented by Bezier nodes.

My question is, is there a simple way to derive the y value of a bezier line segment given an x coordinate. Assume that there is no circumstance where more than one y value might exist for a given x value. I don't see anything in the NSBezierPath documentation that indicates that this is supported.

For the purposes I will be putting this to, a close approximation - eg 2% error - would suffice.

Anyone?

dan donaldson
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.


John C. Randolph <email@hidden> (408) 974-8819
Sr. Cocoa Software Engineer,
Apple Worldwide Developer Relations
http://developer.apple.com/cocoa/index.html
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.


References: 
 >Getting cartesian values from Bezier curve question (From: dan donaldson <email@hidden>)

  • Prev by Date: Controlling targets and headers?
  • Next by Date: Scrolling List of Thumbnails?
  • Previous by thread: Re: Getting cartesian values from Bezier curve question
  • Next by thread: Re: Getting cartesian values from Bezier curve question
  • Index(es):
    • Date
    • Thread