Bezier Patches and Surface Curvatures

profileSubi
9efaca5092f2a3c58ce843a74507b1fa_6fb7bad3cf53c60476a356bc285c561d_82.pdf

In[632]:=

ClearAllEvaluate$Context <> "*"

Basic Definition In[633]:=

colorInterpolation[startColor_, endColor_, numCurves_, currentIndex_] :=

Moduler1, g1, b1, r2, g2, b2, fraction, {r1, g1, b1} = startColor;

{r2, g2, b2} = endColor;

(*Calculate the fraction representing the current position between the curves*)

fraction = (currentIndex - 1)  (numCurves - 1);

(*Interpolate the color components separately*)

RGBColorr1 + fraction (r2 - r1), g1 + fraction (g2 - g1), b1 + fraction (b2 - b1)

(*Example usage*)

startColor = {1, 0, 0}; (*Red*)

endColor = {0, 1, 0}; (*Blue*)

numCurves = 9; (*Number of curves in the design*)

(*Calculate colors for three curve pieces*)

curveColors = TablecolorInterpolation[startColor, endColor, numCurves, i], i, numCurves Out[637]=

{ , , , , , , , , }

In[638]:=

globalToLocal[a_, b_, u_] := (u - a)  (b - a)

In[639]:=

bezierPoints = 

{0, 0}, {1, 0} , {2, 0}, {3, 0},

{3, 0}, 4, -5, 5, 5, 6, 0,

{6, 0}, {7, -5}, {8, -3}, 9, 0,

{9, 0}, 10, 3, {11, 0}, 12, 0,

{12, 0}, {14, 0}, {11, 3}, {13, 2},

{{13, 2}, {12, 1}, {15, 1}, {13, 2}},

{14, 3}, 15, 4, 16, 4, 17, 0,

{17, 0}, 18, - 10, -5, 0, {0, 0}

;

Below is very important. It’s the core part: a function that can generate the bezire

curve.

In[640]:=

f[u_] := ModuleindexInbezierPoints = Floor[u] + 1, localVar = u - Floor[u], pts,

pts = bezierPointsindexInbezierPoints; Sumptsi + 1 × BernsteinBasis[3, i, localVar], i, 0, 3

In[641]:=

g1 = ParametricPlotf[t], t, 0, Length@bezierPoints

Out[641]=

5 10 15

-4

-2

2

In[642]:=

bezierLinesGraph =

TableGraphicscurveColorsi, LinebezierPointsi, i, Length[bezierPoints];

In[643]:=

controlPoints = TableGraphicsPointSize[0.02], curveColorsi, PointbezierPointsi,

i, Length@bezierPoints;

In[644]:=

g2 = ParametricPlotf[t], t, 0, Length@bezierPoints, ColorFunction → Function[{x, y, u}, curveColors〚Floor[u] + 1〛], ColorFunctionScaling → False;

2

Plot1

In[645]:=

Show[bezierLinesGraph, g2, controlPoints]

Out[645]=

Plot2

In[646]:=

g1

Out[646]=

5 10 15

-4

-2

2

Plot3 (wait)

In[647]:=

initRec = {-1, 1}, {1, -1};

3

In[648]:=

GraphicsBlue, Disk [{0, 0}, 1.5](*添加蓝⾊填充的Disk*),

Red, Rectangle@@ initRec, Black, Arrow[{{0, 0}, {1, 0}}], Green,

Arrow{0, 0}, {0, 1}, (*添加垂直箭头*)PointSize[0.02], Point[{0, 0}]

Out[648]=

This is very important: The derivative of bazier curve. Ref:

In[649]:=

"https://computergraphics.stackexchange.com/questions/10551/how-to-take-the-derivative-of-

a-b%C3%A9zier-curve#:~:text=We%20obtain%20a%20quadratic%20B,control%20points%20

scaled%20by%20n.";

In[650]:=

firstD[u_] :=

ModuleindexInbezierPoints = Floor[u] + 1, localVar = u - Floor[u], diffs, two,

diffs = Differences /@ bezierPointsindexInbezierPoints; two = 3 Sumdiffsi + 1 × BernsteinBasis2, i, localVar, i, 0, 2;

(*Don't need to convert to a number*)

two〚1〛, two〚2〛

In[651]:=

firstD[0.5]

Out[651]=

{3., 0.}

4

In[652]:=

SecondD[u_] :=

ModuleindexInbezierPoints = Floor[u] + 1, localVar = u - Floor[u], diffs, diffs2, two,

diffs = Differences /@ bezierPointsindexInbezierPoints; diffs2 = Differences /@ diffsindexInbezierPoints; two = 6 Sumdiffsi + 1 × BernsteinBasis1, i, localVar, i, 0, 1;

(*Don't need to convert to a number*)

two〚1〛, two〚2〛

Plot4

In[653]:=

ManipulateModulecurve, tangent, tangentVector, u, perpendicularVector,

translationMatrix, rotationMatrix, movingRectangle, u = uValue;

curve = f[u];

tangent = firstD[u];

tangentVector = tangent;

perpendicularVector = {-tangentVector〚2〛, tangentVector〚1〛}; translationMatrix = TranslationTransform[curve];

rotationMatrix = RotationTransform[{{1, 0}, tangentVector}];

movingRectangle =

GeometricTransformation[Rectangle@@ initRec, translationMatrix.rotationMatrix];

blueDisk = Disk[curve, 1.5];

ShowGraphicsBlue, blueDisk (*添加蓝⾊填充的Disk*), Red,

movingRectangle, Black, Arrowcurve, curve + Normalize[tangentVector], Green, Arrowcurve, curve + Normalize[perpendicularVector], (*添加垂直箭头*)PointSize[0.02], Point[curve], g1,

uValue, 0, "Parameter u", 0, Length@bezierPoints - 0.02,

0.001, Appearance → "Labeled"

Out[653]=

Parameter u 0

Show , g1

5