﻿ Euler Math Toolbox - Tutorials

# Christmas Stars and Envelopes

The idea to the following plots is due to Ron Gerber. He did that using my geometry program C.a.R.

The following flower shape is well known.

```>x=linspace(0,2pi,1000); ...
plot2d(cos(4*x)*cos(x),cos(4*x)*sin(x)):
``` Now take the points in steps of 1°.

```>x=(0:360)°; ...
plot2d(cos(4*x)*cos(x),cos(4*x)*sin(x),>points):
``` If we connect every 31st point, we get a very nice shape.

```>fullwindow; ...
x=mod((0:360)*31,360)°; ...
plot2d(cos(4*x)*cos(x),cos(4*x)*sin(x),grid=0,r=1):
``` Ron procuded other shapes adding parameters. ```>function plotstar ([m,e,r]) ...
fullwindow();
m=floor(m); e=floor(e); r=floor(r);
x=mod((0:360)*r,360)°;
plot2d(cos(m*x)^e*cos(x),cos(m*x)^e*sin(x),grid=0);
endfunction
```

Using dragvalues(), you can experience various nice shapes.

```>v=dragvalues("plotstar",["M","E","R"],[4,2,31],[0,12;1,10;1,50]); ...
plotstar(v):
``` # Compute Envelopes

The curves that appear in the plots above are envelopes of sets of lines. We can compute such envelopes using the intersections of each two lines.

First the curve.

```>function g(t) := cos(4*t)*[cos(t);sin(t)]; ...
t=(0:361)°; P=g(t); ...
fullwindow(); plot2d(P,P,r=0.95,grid=0):
``` Now we compute the curve with an offset of 31°.

```>Q=g(t+31°);
```

We add the line segments connecting the points of P and Q to the plot.

```>plot2d((P_Q)',(P_Q)',color=gray,>add,thickness=0.5):
``` To compute the envelope, we intersect pairs of these segments using simple linear algebra. In our case, everything works and no two lines are parallel.

```>function getenv (P,Q) ...
n=cols(P);
E=zeros(2,n-1);
D=Q-P;
for i=1 to n-1;
A=D[,[i,i+1]];
b=P[,i]-P[,i+1];
x=A\b;
E[,i]=P[,i]-x*D[,i];
end;
return E;
endfunction
```
```>E=getenv(P,Q); ... ```>reset;