Beispiel #1
0
// This should maybe be a plane method.
func PlaneIntersectionAt(plane *Plane, line *Line, target vec.Vector) float64 {
	dist := (plane.anchorDotNormal - vec.Dot(line.Anchor, plane.Normal)) /
		vec.Dot(line.Normal, plane.Normal)

	if target == nil {
		return dist
	}

	line.Normal.ScaleAt(dist, target)
	vec.AddAt(line.Anchor, target, target)
	return dist
}
Beispiel #2
0
func NewPlane(anchor, normal vec.Vector) *Plane {
	if len(anchor) != len(normal) {
		panic("")
	}

	plane := new(Plane)
	plane.Anchor = make([]float64, len(anchor))
	copy(plane.Anchor, anchor)
	plane.Normal = normal.Normalize()
	plane.anchorDotNormal = vec.Dot(plane.Anchor, plane.Normal)

	return plane
}