B-spline: Difference between revisions
→{{header|ALGOL 68}}: Use spaces instead of tabs, tweak
m (→{{header|Wren}}: Changed to Wren S/H) |
(→{{header|ALGOL 68}}: Use spaces instead of tabs, tweak) |
||
Line 27:
=={{header|ALGOL 68}}==
{{Trans|Lua}}Which is {{Trans|Wren}}Suppresses unused parts of the plot.
<syntaxhighlight lang="algol68">
BEGIN # construct a B-Spline #
# mode to hold a B Spline #
Line 39 ⟶ 40:
[ lb : ub ]INT range;
FOR n FROM lb TO ub DO range[ n ] := n OD;
END # uniform knot vector # ;
PROC calculate bspline = ( REF BSPLINE bs, INT i, k, x )REAL:
THEN ABS ( ( t OF bs )[ i ] <= x AND x < ( t OF bs )[ i + 1 ] )
PROC helper = ( REF BSPLINE bs, INT i, k, x )REAL:
IF ( t OF bs )[ i + k ] /= ( t OF bs )[ i ]
Line 65 ⟶ 66:
REAL sum x := 0;
REAL sum y := 0;
REAL f = calculate bspline( bs, i, k OF bs, x );
sum x +:= f * ( control points OF bs )[ i, 1 ];
sum y +:= f * ( control points OF bs )[ i, 2 ]
OD;
points[ x, 2 ] := round( sum y )
OD;
Line 80 ⟶ 81:
INT x := x0;
INT y := y0;
INT dy := ABS ( y2 - y );
INT dir y = IF y2 > y THEN 1 ELSE -1 FI;
dx *:= 2;
dy *:= 2;
Line 98 ⟶ 99:
PROC plot line = ( REF[,]BOOL plot, INT x1, y1, x2, y2 )VOID:
, ( REF[,]BOOL plot, INT x, INT y )VOID: IF x >= 0
AND y >= 0
Line 104 ⟶ 105:
AND y < 2 UPB plot
THEN plot[ x + 1, y + 1 ] := TRUE
);
PROC plot bspline = ( REF BSPLINE bs, REF[,]BOOL plot, REAL scale x, scale y )VOID:
IF k OF bs > n OF bs OR k OF bs < 1 THEN
print( ( "k (= ", whole( k OF bs, 0 ), ") can't be more than ", whole( n OF bs, 0 )
print( ( " or less than 1.", newline ) );
stop
ELSE
Line 122 ⟶ 124:
)
OD
# print the plot - outputs @ or blank depending on whether the point is plotted or not #
Line 163 ⟶ 165:
);
INT k = 4; # Polynomial degree is one less than this i.e. cubic. #
BSPLINE bs := ( control points
, UPB control points
, k
Line 176 ⟶ 177:
plot bspline( bs, plot, scale x, scale y );
print plot( plot )
END
{{out}}
leading blank lines removed...
<pre>
@@@@
@@@@
Line 220 ⟶ 223:
</pre>
=={{header|Julia}}==
Choose BSpline D of 2, ie degree 1.
|