• 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: Finding point on Bezier curve?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Finding point on Bezier curve?


  • Subject: Re: Finding point on Bezier curve?
  • From: "John C. Randolph" <email@hidden>
  • Date: Thu, 28 Feb 2002 14:34:33 -0800

On Wednesday, February 27, 2002, at 06:28 PM, Salter, Adam Q wrote:

Is it possible to find a point on a Bezier Curve?
I am thinking of implementing an animation routine and I would like to use
Bezier curves... Is this possible?

It sure is, and the math's not even all that tricky. This function does the cubic Bezier interpolation in a single dimension, given four control values:

float bezierInterpolation(float t, float a, float b, float c, float d)
{
float
tSquared, tCubed;
tSquared = t * t;
tCubed = tSquared * t;
return (a
+ (-a * 3 + t * (3 * a - a * t))) * t
+ (3 * b + t * (-6 * b + b * 3 * t)) * t
+ (c * 3 - c * 3 * t) * tSquared
+ d * tCubed;
}

"t" should be a value between zero and one.

(I forget where I got this.. I might have derived it from the explanation of Bezier Cubic Curves in the old Adobe purple book.)

I've used this to indicate a point, like so:

[self drawCrosshairsAtPoint:
NSMakePoint(bezierInterpolation(t, p0.x, p1.x, p2.x, p3.x),
bezierInterpolation(t, p0.y, p1.y, p2.y, p3.y))];

where p0..p3 are NSPoints.

ie follow the curve from the start to the finish, over time...

I can send you some code off-list that draws a bezier curve, and then draws cross-hairs to show X and Y for a given T.

-jcr


John C. Randolph <email@hidden> (408) 974-8819
Sr. Cocoa Software Engineer,
Apple Worldwide Developer Relations
_______________________________________________
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: 
 >Finding point on Bezier curve? (From: "Salter, Adam Q" <email@hidden>)

  • Prev by Date: Why doesn't this work? (NSURL loadResourceDataNotifyingClient)
  • Next by Date: Contextual Menu not showing up in OLV
  • Previous by thread: Re: Finding point on Bezier curve?
  • Next by thread: Re: Curl GUI wrapper using NSTask == no output?
  • Index(es):
    • Date
    • Thread