Exemple #1
0
func NewLine(anchor, normal vec.Vector) *Line {
	if len(anchor) != len(normal) {
		panic("")
	}

	line := new(Line)
	line.Anchor = make([]float64, len(anchor))
	copy(line.Anchor, anchor)
	line.Normal = normal.Normalize()
	return line
}
Exemple #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
}
Exemple #3
0
func NewFinitePlane(anchor, coplanarX, coplanarY vec.Vector, width, height float64) *FinitePlane {
	if len(anchor) != len(coplanarX) || len(anchor) != len(coplanarY) {
		panic("")
	}

	plane := new(FinitePlane)
	plane.Width = width
	plane.Height = height
	plane.CoplanarX = coplanarX.Normalize()
	plane.CoplanarY = coplanarY.Normalize()
	plane.Normal = vec.Cross(plane.CoplanarX, plane.CoplanarY)

	// If coplanarX and coplanarY are colinear, we'll have issues.
	if num.AlmostEqual(0.0, plane.Normal.Norm()) {
		panic("")
	}

	return plane
}
Exemple #4
0
func NewFiniteLine(anchor, normal vec.Vector, length float64) *FiniteLine {
	if len(anchor) != len(normal) {
		panic("")
	}

	line := new(FiniteLine)
	line.Anchor = make([]float64, len(anchor))
	copy(line.Anchor, anchor)
	line.Normal = normal.Normalize()

	if length < 0 {
		line.Length = length * -1
		line.Normal.ScaleAt(-1, line.Normal)
	} else {
		line.Length = length
	}

	return line
}