-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathbezier0.scad
122 lines (101 loc) · 2.47 KB
/
bezier0.scad
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
joinfactor = 0.125;
gFocalPoint = [0,0];
gSteps = 10;
gHeight = 4;
BezQuadCurve( [[0, 15],[5,5],[10,5],[15,15]], [7.5,0], gSteps, gHeight);
//=======================================
// Functions
//=======================================
function BEZ03(u) = pow((1-u), 3);
function BEZ13(u) = 3*u*(pow((1-u),2));
function BEZ23(u) = 3*(pow(u,2))*(1-u);
function BEZ33(u) = pow(u,3);
function PointAlongBez4(p0, p1, p2, p3, u) = [
BEZ03(u)*p0[0]+BEZ13(u)*p1[0]+BEZ23(u)*p2[0]+BEZ33(u)*p3[0],
BEZ03(u)*p0[1]+BEZ13(u)*p1[1]+BEZ23(u)*p2[1]+BEZ33(u)*p3[1]];
//=======================================
// Modules
//=======================================
// c - ControlPoints
module BezQuadCurve(c, focalPoint, steps=gSteps, height=gHeight)
{
// Draw control points
// Just comment this out when you're doing the real thing
for(point=[0:3])
{
translate(c[point])
color([1,0,0])
cylinder(r=1, h=height+joinfactor);
}
for(step = [steps:1])
{
linear_extrude(height = height, convexity = 10)
polygon(
points=[
focalPoint,
PointAlongBez4(c[0], c[1], c[2],c[3], step/steps),
PointAlongBez4(c[0], c[1], c[2],c[3], (step-1)/steps)],
paths=[[0,1,2,0]]
);
}
}
//==============================================
// Test functions
//==============================================
//PlotBEZ0(100);
//PlotBEZ1(100);
//PlotBEZ2(100);
//PlotBEZ3(100);
//PlotBez4Blending();
module PlotBEZ0(steps)
{
cubeSize = 1;
cubeHeight = steps;
for (step=[0:steps])
{
translate([cubeSize*step, 0, 0])
cube(size=[cubeSize, cubeSize, BEZ03(step/steps)*cubeHeight]);
}
}
module PlotBEZ1(steps)
{
cubeSize = 1;
cubeHeight = steps;
for (step=[0:steps])
{
translate([cubeSize*step, 0, 0])
cube(size=[cubeSize, cubeSize, BEZ13(step/steps)*cubeHeight]);
}
}
module PlotBEZ2(steps)
{
cubeSize = 1;
cubeHeight = steps;
for (step=[0:steps])
{
translate([cubeSize*step, 0, 0])
cube(size=[cubeSize, cubeSize, BEZ23(step/steps)*cubeHeight]);
}
}
module PlotBEZ3(steps)
{
cubeSize = 1;
cubeHeight = steps;
for (step=[0:steps])
{
translate([cubeSize*step, 0, 0])
cube(size=[cubeSize, cubeSize, BEZ33(step/steps)*cubeHeight]);
}
}
module PlotBez4Blending()
{
sizing = 100;
translate([0, 0, sizing + 10])
PlotBEZ0(100);
translate([sizing+10, 0, sizing + 10])
PlotBEZ1(100);
translate([0, 0, 0])
PlotBEZ2(100);
translate([sizing+10, 0, 0])
PlotBEZ3(100);
}