Bresenham tasks in ATS: Difference between revisions
Content added Content deleted
No edit summary |
No edit summary |
||
Line 1,156: | Line 1,156: | ||
[[File:Bresenham tasks ATS some quadratics.png|alt=An oval made of four quadratic splines, each spline in a different color, with an aqua background.]] |
[[File:Bresenham tasks ATS some quadratics.png|alt=An oval made of four quadratic splines, each spline in a different color, with an aqua background.]] |
||
[[File:Bresenham tasks ATS some cubics.png|alt=Cubic splines in multiple colors. There is a variety of cusps, inflections, self-intersections, closedness, and sometimes not the whole spline fits in the window.]] |
[[File:Bresenham tasks ATS some cubics.png|alt=Cubic splines in multiple colors. There is a variety of cusps, inflections, self-intersections, closedness, and sometimes not the whole spline fits in the window.]] |
||
===A Maxima script I used=== |
|||
It might be useful if I posted the Maxima script I used to help me devise some of the Bézier curve code. The Maxima commands are not organized well, nor documented well, but nevertheless it might prove useful: |
|||
<syntaxhighlight lang="maxima"> |
|||
/* sbern <--> spow */ |
|||
T1i : matrix( |
|||
[1, 0], |
|||
[0, 1]); |
|||
T1 : invert(T1i); |
|||
T2i : matrix( |
|||
[1, 0, 0], |
|||
[1, 1, 1], |
|||
[0, 0, 1]); |
|||
T2 : invert(T2i); |
|||
T3i : matrix( |
|||
[1, 0, 0, 0], |
|||
[2, 1, 0, 1], |
|||
[1, 0, 1, 2], |
|||
[0, 0, 0, 1]); |
|||
T3 : invert(T3i); |
|||
expand(T1.matrix([c0],[c1])); |
|||
expand(T2.matrix([c0],[c1],[c2])); |
|||
expand(T3.matrix([c0],[c1],[c2],[c3])); |
|||
/* sbern <--> mono */ |
|||
S1i : transpose(matrix( |
|||
[1, -1], |
|||
[0, 1])); |
|||
S1 : invert(S1i); |
|||
S2i : transpose(matrix( |
|||
[1, -2, 1], |
|||
[0, 1, -1], |
|||
[0, 0, 1])); |
|||
S2 : invert(S2i); |
|||
S3i : transpose(matrix( |
|||
[1, -3, 3, -1], |
|||
[0, 1, -2, 1], |
|||
[0, 0, 1, -1], |
|||
[0, 0, 0, 1])); |
|||
S3 : invert(S3i); |
|||
F1 : expand(S1i.T1i.matrix([c0],[c1])); |
|||
F2 : expand(S2i.T2i.matrix([c0],[c1],[c2])); |
|||
F3 : expand(S3i.T3i.matrix([c0],[c1],[c2],[c3])); |
|||
/* portion t0..t1 */ |
|||
g(x) := t0 + ((t1 - t0) * x); |
|||
f2(x) := expand(F2.matrix([1],[x],[x**2])); |
|||
expand(T2.S2.matrix( |
|||
[coeff(f2(g(t)), t, 0)], |
|||
[coeff(f2(g(t)), t, 1)], |
|||
[coeff(f2(g(t)), t, 2)])); |
|||
f3(x) := expand(F3.matrix([1],[x],[x**2],[x**3])); |
|||
Solution3 : expand(T3.S3.matrix( |
|||
[coeff(f3(g(t)), t, 0)], |
|||
[coeff(f3(g(t)), t, 1)], |
|||
[coeff(f3(g(t)), t, 2)], |
|||
[coeff(f3(g(t)), t, 3)])); |
|||
Solution3[1]; |
|||
Solution3[2]; |
|||
Solution3[3]; |
|||
Solution3[4]; |
|||
/* derivatives and critical points */ |
|||
/* In s-power format: */ |
|||
Mx : S3i.T3i.matrix([cx0],[cx1],[cx2],[cx3]); |
|||
My : S3i.T3i.matrix([cy0],[cy1],[cy2],[cy3]); |
|||
fx(t) := expand(transpose(Mx).matrix([1],[t],[t**2],[t**3])); |
|||
fy(t) := expand(transpose(My).matrix([1],[t],[t**2],[t**3])); |
|||
fxp(t) := diff(fx(t), t); |
|||
fxpp(t) := diff(fxp(t), t); |
|||
fyp(t) := diff(fy(t), t); |
|||
fypp(t) := diff(fyp(t), t); |
|||
cross(t) := expand((fxp(t) * fypp(t)) - (fyp(t) * fxpp(t))); |
|||
expand(fxp(t)); |
|||
expand(fyp(t)); |
|||
expand(cross(t) / 2); /* Notice that this is quadratic. */ |
|||
/* Translating the first endpoint to (0,0), and the second to |
|||
cx3 - cx0. */ |
|||
Mx : S3i.T3i.matrix([0],[cx1],[cx2],[cx3m0]); |
|||
My : S3i.T3i.matrix([0],[cy1],[cy2],[cy3m0]); |
|||
fx(t) := expand(transpose(Mx).matrix([1],[t],[t**2],[t**3])); |
|||
fy(t) := expand(transpose(My).matrix([1],[t],[t**2],[t**3])); |
|||
fxp(t) := diff(fx(t), t); |
|||
fxpp(t) := diff(fxp(t), t); |
|||
fyp(t) := diff(fy(t), t); |
|||
fypp(t) := diff(fyp(t), t); |
|||
cross(t) := expand((fxp(t) * fypp(t)) - (fyp(t) * fxpp(t))); |
|||
expand(fxp(t)); |
|||
expand(fyp(t)); |
|||
expand(cross(t) / 2); /* Notice that this is quadratic. */ |
|||
</syntaxhighlight> |
|||
Some of the calculations are done by assigning names to the coefficients of splines in the s-power basis, finding the corresponding coefficients in the ordinary monomial basis, then (using Maxima's inherent capabilities) performing an operation such as composition or differentiation. It is a sloppy script. |