Пример #1
0
// face returns face ID from 0 to 5 containing the r. For points on the
// boundary between faces, the result is arbitrary but deterministic.
func face(r r3.Vector) int {
	abs := r.Abs()
	id := 0
	value := r.X
	if abs.Y > abs.X {
		id = 1
		value = r.Y
	}
	if abs.Z > math.Abs(value) {
		id = 2
		value = r.Z
	}
	if value < 0 {
		id += 3
	}
	return id
}
Пример #2
0
func TrueCentroid(a, b, c Point) interface{} {
	angleA := b.Angle(c.Vector).Radians()
	angleB := c.Angle(a.Vector).Radians()
	angleC := a.Angle(b.Vector).Radians()
	ra, rb, rc := 1., 1., 1.
	if angleA != 0 {
		ra = angleA / math.Sin(angleA)
	}
	if angleB != 0 {
		rb = angleB / math.Sin(angleB)
	}
	if angleC != 0 {
		rc = angleC / math.Sin(angleC)
	}

	x := r3.Vector{a.X, b.X - a.X, c.X - a.X}
	y := r3.Vector{a.Y, b.Y - a.Y, c.Y - a.Y}
	z := r3.Vector{a.Z, b.Z - a.Z, c.Z - a.Z}
	r := r3.Vector{ra, rb - ra, rc - ra}
	v := r3.Vector{
		y.Cross(z).Dot(r),
		z.Cross(x).Dot(r),
		x.Cross(y).Dot(r),
	}
	return Point{v.Mul(0.5)}
}