Last active
August 30, 2020 10:39
-
-
Save hyrodium/9c0130f660ab5430746319ab498a0fe9 to your computer and use it in GitHub Desktop.
Snake curve by B-spline
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using BasicBSpline | |
using ExportNURBS | |
using Colors | |
p = 3 | |
f(u) = [u[1],sin(u[1])] | |
N = 80 | |
w = 5 | |
W = 7 | |
for i in 1:N | |
t = (w+W)-i/N * 2*(w+W) | |
a,b = -w-t, w-t | |
nnn = 4 | |
global k = Knots(range(a,b,length=nnn-p+1))+p*Knots(a,b) | |
global P = FastBSplineSpace(p, k) | |
global a = fittingcontrolpoints(f, [P]) | |
global M = BSplineManifold([P],a) | |
save_png("docs/src/img/sine_curve_a"*lpad(i,3,"0")*".png", M, unitlength=50, up=3, down=-3, left=-W, right=W, thickness=2, backgroundcolor=RGB(1,0.8,0.8), linecolor=RGB(1,0,0)) | |
end | |
for i in 1:N | |
t = (w+W)-i/N * 2*(w+W) | |
a,b = -w-t, w-t | |
nnn = 5 | |
global k = Knots(range(a,b,length=nnn-p+1))+p*Knots(a,b) | |
global P = FastBSplineSpace(p, k) | |
global a = fittingcontrolpoints(f, [P]) | |
global M = BSplineManifold([P],a) | |
save_png("sine_curve_b"*lpad(i,3,"0")*".png", M, unitlength=50, up=3, down=-3, left=-W, right=W, thickness=2, backgroundcolor=RGB(0.9,0.9,0.8), linecolor=RGB(0.5,0.5,0)) | |
end | |
for i in 1:N | |
t = (w+W)-i/N * 2*(w+W) | |
a,b = -w-t, w-t | |
nnn = 6 | |
global k = Knots(range(a,b,length=nnn-p+1))+p*Knots(a,b) | |
global P = FastBSplineSpace(p, k) | |
global a = fittingcontrolpoints(f, [P]) | |
global M = BSplineManifold([P],a) | |
save_png("sine_curve_c"*lpad(i,3,"0")*".png", M, unitlength=50, up=3, down=-3, left=-W, right=W, thickness=2, backgroundcolor=RGB(0.8,1,0.8), linecolor=RGB(0,1,0)) | |
end | |
for i in 1:N | |
t = (w+W)-i/N * 2*(w+W) | |
a,b = -w-t, w-t | |
nnn = 7 | |
global k = Knots(range(a,b,length=nnn-p+1))+p*Knots(a,b) | |
global P = FastBSplineSpace(p, k) | |
global a = fittingcontrolpoints(f, [P]) | |
global M = BSplineManifold([P],a) | |
save_png("sine_curve_d"*lpad(i,3,"0")*".png", M, unitlength=50, up=3, down=-3, left=-W, right=W, thickness=2, backgroundcolor=RGB(0.8,0.9,0.9), linecolor=RGB(0,0.5,0.5)) | |
end | |
for i in 1:N | |
t = (w+W)-i/N * 2*(w+W) | |
a,b = -w-t, w-t | |
nnn = 8 | |
global k = Knots(range(a,b,length=nnn-p+1))+p*Knots(a,b) | |
global P = FastBSplineSpace(p, k) | |
global a = fittingcontrolpoints(f, [P]) | |
global M = BSplineManifold([P],a) | |
save_png("sine_curve_e"*lpad(i,3,"0")*".png", M, unitlength=50, up=3, down=-3, left=-W, right=W, thickness=2, backgroundcolor=RGB(0.8,0.8,1), linecolor=RGB(0,0,1)) | |
end | |
for i in 1:N | |
t = (w+W)-i/N * 2*(w+W) | |
a,b = -w-t, w-t | |
nnn = 30 | |
global k = Knots(range(a,b,length=nnn-p+1))+p*Knots(a,b) | |
global P = FastBSplineSpace(p, k) | |
global a = fittingcontrolpoints(f, [P]) | |
global M = BSplineManifold([P],a) | |
save_png("sine_curve_z"*lpad(i,3,"0")*".png", M, unitlength=50, up=3, down=-3, left=-W, right=W, thickness=2, backgroundcolor=RGB(0.9,0.9,0.9), linecolor=RGB(0.2,0.2,0.2)) | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using BasicBSpline | |
using ExportNURBS | |
using Colors | |
p = 3 | |
f(u) = [u[1],sin(u[1])] | |
N = 80 | |
w = 5 | |
W = 7 | |
for i in 1:N | |
t = (w+W)-i/N * 2*(w+W) | |
a,b = -w-t, w-t | |
nnn = 4 | |
global k = Knots(range(a,b,length=nnn-p+1))+p*Knots(a,b) | |
global P = FastBSplineSpace(p, k) | |
global a = fittingcontrolpoints(f, [P]) | |
global M = BSplineManifold([P],a) | |
save_png("docs/src/img/sine_curve_a"*lpad(i,3,"0")*".png", M, unitlength=50, up=3, down=-3, left=-W, right=W, thickness=2, backgroundcolor=RGB(1,0.8,0.8), linecolor=RGB(1,0,0), points=false) | |
end | |
for i in 1:N | |
t = (w+W)-i/N * 2*(w+W) | |
a,b = -w-t, w-t | |
nnn = 5 | |
global k = Knots(range(a,b,length=nnn-p+1))+p*Knots(a,b) | |
global P = FastBSplineSpace(p, k) | |
global a = fittingcontrolpoints(f, [P]) | |
global M = BSplineManifold([P],a) | |
save_png("sine_curve_b"*lpad(i,3,"0")*".png", M, unitlength=50, up=3, down=-3, left=-W, right=W, thickness=2, backgroundcolor=RGB(0.9,0.9,0.8), linecolor=RGB(0.5,0.5,0), points=false) | |
end | |
for i in 1:N | |
t = (w+W)-i/N * 2*(w+W) | |
a,b = -w-t, w-t | |
nnn = 6 | |
global k = Knots(range(a,b,length=nnn-p+1))+p*Knots(a,b) | |
global P = FastBSplineSpace(p, k) | |
global a = fittingcontrolpoints(f, [P]) | |
global M = BSplineManifold([P],a) | |
save_png("sine_curve_c"*lpad(i,3,"0")*".png", M, unitlength=50, up=3, down=-3, left=-W, right=W, thickness=2, backgroundcolor=RGB(0.8,1,0.8), linecolor=RGB(0,1,0), points=false) | |
end | |
for i in 1:N | |
t = (w+W)-i/N * 2*(w+W) | |
a,b = -w-t, w-t | |
nnn = 7 | |
global k = Knots(range(a,b,length=nnn-p+1))+p*Knots(a,b) | |
global P = FastBSplineSpace(p, k) | |
global a = fittingcontrolpoints(f, [P]) | |
global M = BSplineManifold([P],a) | |
save_png("sine_curve_d"*lpad(i,3,"0")*".png", M, unitlength=50, up=3, down=-3, left=-W, right=W, thickness=2, backgroundcolor=RGB(0.8,0.9,0.9), linecolor=RGB(0,0.5,0.5), points=false) | |
end | |
for i in 1:N | |
t = (w+W)-i/N * 2*(w+W) | |
a,b = -w-t, w-t | |
nnn = 8 | |
global k = Knots(range(a,b,length=nnn-p+1))+p*Knots(a,b) | |
global P = FastBSplineSpace(p, k) | |
global a = fittingcontrolpoints(f, [P]) | |
global M = BSplineManifold([P],a) | |
save_png("sine_curve_e"*lpad(i,3,"0")*".png", M, unitlength=50, up=3, down=-3, left=-W, right=W, thickness=2, backgroundcolor=RGB(0.8,0.8,1), linecolor=RGB(0,0,1), points=false) | |
end | |
for i in 1:N | |
t = (w+W)-i/N * 2*(w+W) | |
a,b = -w-t, w-t | |
nnn = 30 | |
global k = Knots(range(a,b,length=nnn-p+1))+p*Knots(a,b) | |
global P = FastBSplineSpace(p, k) | |
global a = fittingcontrolpoints(f, [P]) | |
global M = BSplineManifold([P],a) | |
save_png("sine_curve_z"*lpad(i,3,"0")*".png", M, unitlength=50, up=3, down=-3, left=-W, right=W, thickness=2, backgroundcolor=RGB(0.9,0.9,0.9), linecolor=RGB(0.2,0.2,0.2), points=false) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment