HP Forums

Full Version: Bézier Curves (Bezier curves)
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
A program for generating and drawing Bézier curves...
Bezier curves V0.1 allows the points on a Bezier curve to be generated and drawn.


 LOCAL CRID:="Bézier V0.1 StephenG1CMZ 2018";

 //LOCAL ImpSTEPSZ:=1/(10000-2);//Most Detailed-List Limit
 //! Android: Insufficient Memory may occur. 
 //These steps allow a spline along a diagonal
 //LOCAL GSTEPSZ:=1/(4406-2); //4K
 //LOCAL GSTEPSZ:=1/(2203-2); //HD
 //LOCAL GSTEPSZ:=1/(800-2);//VGA
 //0..1 ALSO IMP>0.001=10000 PTS

 //Generate a point along a Bezier Quadratic curve
 //PERCY AND II: 0..1

 //Generate Bezier Quadratic curve
  LOCAL PTS:={};
  PTS(0):=GBezierQUAD1(XX,YY,1); //(XX(3),YY(3));

 //Generate a point along a Bezier Cubic curve
 //PERCY AND II: 0..1



 //Generate Bezier Cubic curve
  LOCAL PTS:={};

   PTS(0):=GBezierCUBIC1(XX,YY,II); //X AND Y
  PTS(0):=GBezierCUBIC1(XX,YY,1); //(XX(4),YY(4));

 //CONN 0: POINTS 1 BY 1 


 EXPORT IsOnCurve(Points,Point,Rounding)
 //Is PT on curve described by PTS
 //Points:Points comprising curve
 //Point: Search Point (Complex XY)
 //Rounding: −12..12 allows inexact real matches 
 //NB if points change, conclusion may
 //Enhancements: Consider alternatives to rounding
  LOCAL RND:=Rounding;

 EXPORT BezierExample()
 DRAWC({(320/2,240/2)},COLR,CN);//TEST 1 PT
 TEXTOUT_P(SIZE(PTS)+" Points/Bézier",0,200);
 //PRINT("RESULT:POS is "+IsOnCurve({(1,2)},(1,2),0));


Quadratic Bezier and Cubic Bezier are implemented, but Polybeziers are not yet implemented.
Oh memories!
I learned about Bezier curves about 10 years ago, I used them as a rough approximation of the catenary curve, to draw some wires in a game. Later on I used polybeziers and splines in other projects Smile
When I saw how quickly I got a reply, I was expecting to see "why didn't you use this built-in function?" but I didn't find one.
I know I studied Bezier and splines but I have forgotten most of that and I can't recall ever needing them.
This thread discusses plotting Bezier curves using the plotparam built-in and Parametric App (as
Possible alternative to using this PPL program).

Note: If my program gives a syntax error on a line containing "space)", just delete the space character.
Reference URL's