forked from go-spatial/geom
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpointz.go
42 lines (34 loc) · 766 Bytes
/
pointz.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
package geom
import (
"errors"
"math"
)
// ErrNilPointZ is thrown when a point is null but shouldn't be
var ErrNilPointZ = errors.New("geom: nil PointZ")
// Point describes a simple 3D point
type PointZ [3]float64
// XYZ returns an array of 3D coordinates
func (p PointZ) XYZ() [3]float64 {
return p
}
// XY returns an array of 2D coordinates
func (p PointZ) XY() [2]float64 {
return Point{
p[0],
p[1],
}
}
// SetXYZ sets the three coordinates
func (p *PointZ) SetXYZ(xyz [3]float64) (err error) {
if p == nil {
return ErrNilPointZ
}
p[0] = xyz[0]
p[1] = xyz[1]
p[2] = xyz[2]
return
}
// Magnitude of the point is the size of the point
func (p PointZ) Magnitude() float64 {
return math.Sqrt((p[0] * p[0]) + (p[1] * p[1]) + (p[2] * p[2]))
}