0
votes

I'm using PHP with imagick to draw bezier curves. I have a function that will take 3 x,y coordinates and return the middle XY point to ensure that the curve passes through those 3 points.

I'd like to create a function that does the same thing, but for 6 points. I have no idea where to start. I assume there is a mathematical way to calculate the 4 midpoints in a 6 point bezier curve.

Here is an example of how the 3 point code works:

$s1 = array("x" => $var1, "y" => 0);//start
$s2 = array("x" => $var2, "y" => $var3);
$s3 = array("x" => $var4, "y" => $var5);//end
$smp = findControlPoint($s1, $s2, $s3); 

$points = array
(
    array( 'x' => $s1['x'], 'y' => $s1['y'] ),
    array( 'x' => $smp['x'], 'y' => $smp['y'] ),
    array( 'x' => $s3['x'], 'y' => $s3['y'] ),  

);
$draw->bezier($points); 
1
what is the "midpoint" of a Bezier curve? The point where the control variable is 0.5 (if so, that's easy), or where the length of the curve to the left is equal to the length of the curve on the right? (if so, that's literally impossible to symbolically compute for 3rd and higher order Bezier curves). Secondly, do you mean a single curve made of 6 points, or a poly-Bezier curve (several cubic curves tacked together into a single curve). - Mike 'Pomax' Kamermans
This questions would probably benefit from being moved to math.stackexchange.com - DudeOnRock
@Ryland22 I think you've forgotten to post the code for findControlPoint. However the answer may not depend on that, but the parameters of your question aren't entirely clear. - Danack

1 Answers

0
votes

Your question is slightly confusing as it's not entirely clear how you're generating the points. However to get multiple 4 point bezier curves to be continuous over their 'joins' you need to (from Joining Multiple Bézier Curves ):

Lets take an example where we have two sets of points (A1, A2, A3, & A4 and B1, B2, B3, & B4). In order for these points to create one smooth Bézier curve, the following two facts must be true:

  • They must end on the same point (A4 == B1)
  • A3, A4, and B2 must be colinear (same as saying A3, B1, and B2 must be colinear)

You will need to use more than 3 points per 'section' that you want to join together, as 3 points doesn't give enough control over the direction of the curves at the beginning and end of each section.