(1) CubicBezier1.m : Evaluates Cubic Bezier Curve for given four Control Points and interval.
(2) PlotBezier1.m : Plots Bezier Curve, Control Points, Control Polygon
(3) TestCircleApproxByCubicBezier.m : Test Program. Pass Control Points that approximate unit radius circle using cubic Beizer curves.
(4) ApproxofCirclebyCubicBezier.pdf: Explains theroy.
Dr. Murtaza Khan (2021). Approximation of Circle Using Cubic Bezier Curve (https://www.mathworks.com/matlabcentral/fileexchange/6844-approximation-of-circle-using-cubic-bezier-curve), MATLAB Central File Exchange. Retrieved .
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Create scripts with code, output, and formatted text in a single executable document.
plz send me.
great. example in C for PDF Postscript:
pdf_circle(float midY, float midY, float radius)
{ // incomplete C example
float BX1, BY1, BX2, BY2, Xs, Ys, Xe, Ye, kappa;
fprintf(pdffile, "q\n"); // postscript content in pdf
// init line type etc. with /GSD gs G g (grey) RG rg (RGB) w=line witdh etc.
fprintf(pdffile, "1 j\n"); // line join
// translate ("move") circle to midY, midY
fprintf(pdffile, "1 0 0 1 %f %f cm", midX, midY);
kappa=0.5522847498307933984022516322796;
/* Quadrant 1 */
Xs=0.0; /* 12 o'clock */
Xs=0.0 + radius;
Xe=0.0 + radius; /* 3 o'clock */
Ye=0.0;
fprintf(pdffile "%f %f m\n", Xs, Ys); /* move to 12 o'clock */
/* cubic bezier control point 1, start height and kappa * radius to the right */
BX1=Xs + (radius * kappa);
BY1=Ys;
/* cubic bezier control point 2, end and kappa * radius above */
BX2=Xe;
BY2=Ye + (radius * kappa);
// draw cubic bezier from current point to Xe/Ye with BX1/BY1 and BX2/BY2 as bezier control points
fprintf(pdffile, "%f %f %f %f %f %f c\n", BX1, BY1, BX2, BY2, Xe, Ye);
/* Quadrant 2 */
Xs=Xe; Ys=Ye; /* 3 o'clock */
Xe=0.0; Ye=0.0 - radius; /* 6 o'clock */
BX1=Xs; /* cubic bezier point 1 */
BY1=Ys - (radius * kappa);
BX2=Xe + (radius * kappa); /* cubic bezier point 2 */
BY2=Ye;
fprintf(pdffile, "%f %f %f %f %f %f c\n", BX1, BY1, BX2, BY2, Xe, Ye);
/* Quadrant 3 */
Xs=Xe; Ys=Ye; /* 6 o'clock */
Xe=0.0 - radius; Ye=0.0; /* 9 o'clock */
BX1=Xs - (radius * kappa); /* cubic bezier point 1 */
BY1=Ys;
BX2=Xe; /* cubic bezier point 2 */
BY2=Ye - (radius * kappa);
fprintf(pdffile, "%f %f %f %f %f %f c\n", BX1, BY1, BX2, BY2, Xe, Ye);
/* Quadrant 4 */
Xs=Xe; Ys=Ye; /* 9 o'clock */
Xe=0.0; Ye=0.0 + radius; /* 12 o'clock */
BX1=Xs; /* cubic bezier point 1 */
BY1=Ys + (radius * kappa);
BX2=Xe - (radius * kappa); /* cubic bezier point 2 */
BY2=Ye;
fprintf(pdffile, "%f %f %f %f %f %f c\n", BX1, BY1, BX2, BY2, Xe, Ye);
fprintf(pdffile, "s\n"); /* stroke circle, do not fill and close path */
// for filling etc. b, b*, f, f*
fprintf(pdffile, "Q\n"); // finish postscript in PDF
}
good
Thank you