-
-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathcircle.go
53 lines (39 loc) · 1.27 KB
/
circle.go
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
package repeat
import (
"math"
"github.com/EliCDavis/polyform/math/quaternion"
"github.com/EliCDavis/polyform/math/trs"
"github.com/EliCDavis/polyform/nodes"
"github.com/EliCDavis/vector/vector3"
)
func CirclePoints(count int, radius float64) []vector3.Float64 {
angleIncrement := (1.0 / float64(count)) * 2.0 * math.Pi
final := make([]vector3.Float64, count)
for i := range count {
angle := angleIncrement * float64(i)
final[i] = vector3.New(math.Cos(angle)*radius, 0, math.Sin(angle)*radius)
}
return final
}
func Circle(times int, radius float64) []trs.TRS {
angleIncrement := (1.0 / float64(times)) * 2.0 * math.Pi
transforms := make([]trs.TRS, times)
for i := range times {
angle := angleIncrement * float64(i)
pos := vector3.New(math.Cos(angle), 0, math.Sin(angle)).Scale(radius)
rot := quaternion.FromTheta(angle-(math.Pi/2), vector3.Down[float64]())
transforms[i] = trs.New(pos, rot, vector3.One[float64]())
}
return transforms
}
type CircleNode = nodes.Struct[CircleNodeData]
type CircleNodeData struct {
Radius nodes.Output[float64]
Times nodes.Output[int]
}
func (r CircleNodeData) Out() nodes.StructOutput[[]trs.TRS] {
return nodes.NewStructOutput(Circle(
nodes.TryGetOutputValue(r.Times, 3),
nodes.TryGetOutputValue(r.Radius, 1.),
))
}