示例#1
0
// Normalize normalizes the vector.
func (v Vec3) Normalize() {
	d := 1.0 / math32.Sqrt(v[0]*v[0]+v[1]*v[1]+v[2]*v[2])
	v[0] *= d
	v[1] *= d
	v[2] *= d
}
示例#2
0
// Dist2D derives the distance between v and v2 on the xz-plane.
//
// The vectors are projected onto the xz-plane, so the y-values are ignored.
func (v Vec3) Dist2D(v1 Vec3) float32 {
	dx := v1[0] - v[0]
	dz := v1[2] - v[2]
	return math32.Sqrt(dx*dx + dz*dz)
}
示例#3
0
// LenSqr derives the scalar scalar length of the vector. (len)
func (v Vec3) Len() float32 {
	return math32.Sqrt(v[0]*v[0] + v[1]*v[1] + v[2]*v[2])
}
示例#4
0
// Dist returns the distance between v and v1. d = dist(v, v2)
func (v Vec3) Dist(v1 Vec3) float32 {
	dx := v1[0] - v[0]
	dy := v1[1] - v[1]
	dz := v1[2] - v[2]
	return math32.Sqrt(dx*dx + dy*dy + dz*dz)
}
示例#5
0
// Dist returns the distance between v and v1. d = dist(v, v2)
func (v Vec2) Dist(v1 Vec2) float32 {
	dx := v1[0] - v[0]
	dy := v1[1] - v[1]
	return math32.Sqrt(dx*dx + dy*dy)
}