-
Notifications
You must be signed in to change notification settings - Fork 30
/
extruder.go
39 lines (36 loc) · 965 Bytes
/
extruder.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
package dxf
import (
"github.com/yofu/dxf/geometry"
)
// Extruder represents an entity with code 210, 220, 230 like Circle.
// 210: Extrusion direction (optional; default = 0, 0, 1)
// X value
// 220, 230: Y and Z values of extrusion direction (optional)
type Extruder interface { // 210 220 230
CurrentDirection() []float64
SetDirection([]float64)
CurrentCoord() []float64
SetCoord([]float64)
}
// SetExtrusion sets new coord acoording to given direction.
func SetExtrusion(e Extruder, d []float64) {
dx, dy, err := geometry.ArbitraryAxis(d)
if err != nil {
return
}
b := e.CurrentDirection()
e.SetDirection(d)
n := e.CurrentCoord()
bx, by, _ := geometry.ArbitraryAxis(b)
before := [][]float64{bx, by, b}
after := [][]float64{dx, dy, d}
newcoord := make([]float64, 3)
for i := 0; i < 3; i++ {
for j := 0; j < 3; j++ {
for k := 0; k < 3; k++ {
newcoord[i] += n[j] * before[j][k] * after[i][k]
}
}
}
e.SetCoord(newcoord)
}