File Exchange

## Approximation of Circle Using Cubic Bezier Curve

version 1.1.0.0 (118 KB) by Dr. Murtaza Khan

### Dr. Murtaza Khan (view profile)

Approximation of unit radius circle with four parametrix bezier curves

Updated 09 Jul 2009

(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.

Arsentii Kambalin

### Arsentii Kambalin (view profile)

payam pourali

plz send me.

fung hinbon

M Kommant

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;
Xs=0.0; /* 12 o'clock */
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 */
BY1=Ys;
/* cubic bezier control point 2, end and kappa * radius above */
BX2=Xe;
// 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);
Xs=Xe; Ys=Ye; /* 3 o'clock */
Xe=0.0; Ye=0.0 - radius; /* 6 o'clock */
BX1=Xs; /* cubic bezier point 1 */
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);
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 */
fprintf(pdffile, "%f %f %f %f %f %f c\n", BX1, BY1, BX2, BY2, Xe, Ye);
Xs=Xe; Ys=Ye; /* 9 o'clock */
Xe=0.0; Ye=0.0 + radius; /* 12 o'clock */
BX1=Xs; /* cubic bezier point 1 */
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
}

bharat chauhan

good

chandra sekahr

youngnam kang

Thank you