-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathStandardPaths.ele
96 lines (90 loc) · 3.11 KB
/
StandardPaths.ele
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
#[[ Standard Paths are pre-defined Paths. They all have the domain (0, 1).
#
# If the path length is possible to calculate analytically, a separate
# function is defined to provide it. Note that applying transforms
# to these paths may change the path length.
#]]
namespace StandardPaths
{
#[[ An anti-clockwise circle in the x-y plane, beginning at
# x=radius, y=0
#]]
circle(radius:Num):Path
{
circleFunction(u:Num):Vector3
{
x = radius.mul(Num.cos(u.mul(Num.tau)))
y = radius.mul(Num.sin(u.mul(Num.tau)))
return = Vector3(x, y, 0)
}
return = Path(circleFunction, Bounds(0, 1))
}
circleLength(radius:Num):Num = Num.tau.mul(radius)
#[[ A straight line from point 'a' to point 'b' ]]
line(a:Vector3, b:Vector3):Path
{
lineFunction(u:Num):Vector3 = Vector3.lerp(u, a, b)
return = Path(lineFunction, Bounds(0, 1))
}
lineLength(a:Vector3, b:Vector3):Num = Vector3.distance(a, b)
#[[ A rectangle in the x-y plane, starting at the origin
#
# Goes clockwise to the points:
# (0, 0, 0), (0, height, 0), (width, height, 0), (width, 0, 0)
# in that order.
#]]
rectangle(width:Num, height:Num):Path
{
pointA = Vector3(0, 0, 0)
pointB = Vector3(0, height, 0)
pointC = Vector3(width, height, 0)
pointD = Vector3(width, 0, 0)
return = Path.concatAll(
list(
{path=line(pointA, pointB), length=height},
{path=line(pointB, pointC), length=width},
{path=line(pointC, pointD), length=height},
{path=line(pointD, pointA), length=width}
)
)
}
rectangleLength(width:Num, height:Num):Num = 2.mul(width.add(height))
#[[ Create a lissajous curve in the x-y plane.
#
# The frequencies must be integers for the
# path to start and end at the same position.
#]]
lissajous(radii:Vector2, frequencies:Vector2, phaseDifference:Num):Path
{
omega = frequencies.scale(Num.tau) # Angular Frequencies
lissajousFunction(u:Num):Vector3
{
xPhase = u.mul(omega.x)
yPhase = u.mul(omega.y).add(phaseDifference)
xProgress = Num.sin(xPhase)
yProgress = Num.sin(yPhase)
xPos = xProgress.mul(radii.x)
yPos = yProgress.mul(radii.y)
return = Vector3(xPos, yPos, 0)
}
return = Path(lissajousFunction, Bounds(0, 1))
}
#[[ Create a rose curve in the x-y plane.
#
# The petalConstant must be an integer for the
# path to start and end at the same position.
#]]
rose(radius:Num, frequency:Num, petalConstant:Num):Path
{
omega = frequency.mul(Num.tau)
roseFunction(u:Num):Vector3
{
phase = omega.mul(u)
roseFactor = Num.cos(petalConstant.mul(phase))
xPos = Num.cos(phase).mul(roseFactor)
yPos = Num.sin(phase).mul(roseFactor)
return = Vector3(xPos, yPos, 0)
}
return = Path(roseFunction, Bounds(0, 1))
}
}