utils_math library
Properties
final VX_AXIS #
final VX_AXIS = new Vector3(1.0, 0.0, 0.0)
final VY_AXIS #
final VY_AXIS = new Vector3(0.0, 1.0, 0.0)
final VZ_AXIS #
final VZ_AXIS = new Vector3(0.0, 0.0, 1.0)
final VZERO #
final VZERO = new Vector3.zero()
Functions
MinMax extractMinMaxProjection(List<Vector3> vs, Vector3 axis, MinMax out) #
the MinMax use axis as unit vector, and (0,0,0) as origin point.
MinMax extractMinMaxProjection(List<Vector3> vs, Vector3 axis, MinMax out) { var p = vs[0].dot(axis); out.min = p; out.max = p; for (int i = 1; i < vs.length; i++) { p = vs[i].dot(axis); if (p < out.min) out.min = p; if (p > out.max) out.max = p; } }
Aabb3 extractAabbPoly2(List<Vector3> vs0, List<Vector3> vs1, Aabb3 out) #
Aabb3 extractAabbPoly2(List<Vector3> vs0, List<Vector3> vs1, Aabb3 out){ var min = out.min; var max = out.max; min.setFrom(vs0[0]); max.setFrom(vs0[0]); var vs = vs0; for (int i = vs.length - 1; i > 0 ; --i) { var v = vs[i]; if (min.x > v.x) min.x = v.x; if (min.y > v.y) min.y = v.y; if (min.z > v.z) min.z = v.z; if (max.x < v.x) max.x = v.x; if (max.y < v.y) max.y = v.y; if (max.z < v.z) max.z = v.z; } vs = vs1; for (int i = vs.length - 1; i >= 0; --i) { var v = vs[i]; if (min.x > v.x) min.x = v.x; if (min.y > v.y) min.y = v.y; if (min.z > v.z) min.z = v.z; if (max.x < v.x) max.x = v.x; if (max.y < v.y) max.y = v.y; if (max.z < v.z) max.z = v.z; } return out; }
Aabb3 extractAabbPoly(List<Vector3> vs, Aabb3 out) #
Aabb3 extractAabbPoly(List<Vector3> vs, Aabb3 out){ var min = out.min; var max = out.max; min.setFrom(vs[0]); max.setFrom(vs[0]); for (int i = vs.length - 1; i > 0 ; --i) { var v = vs[i]; if (min.x > v.x) min.x = v.x; if (min.y > v.y) min.y = v.y; if (min.z > v.z) min.z = v.z; if (max.x < v.x) max.x = v.x; if (max.y < v.y) max.y = v.y; if (max.z < v.z) max.z = v.z; } return out; }
Aabb3 extractAabbDisc2(Vector3 v0, Vector3 v1, double radius, Aabb3 out) #
Aabb3 extractAabbDisc2(Vector3 v0, Vector3 v1, double radius, Aabb3 out){ var min = out.min; var max = out.max; if (v0.x < v1.x) { min.x = v0.x - radius; max.x = v1.x + radius; } else { min.x = v1.x - radius; max.x = v0.x + radius; } if (v0.y < v1.y) { min.y = v0.y - radius; max.y = v1.y + radius; } else { min.y = v1.y - radius; max.y = v0.y + radius; } if (v0.z < v1.z) { min.z = v0.z - radius; max.z = v1.z + radius; } else { min.z = v1.z - radius; max.z = v0.z + radius; } //out.min.setValues(math.min(v0.x, v1.x) - radius, math.min(v0.y, v1.y) - radius, math.min(v0.z, v1.z) - radius); //out.max.setValues(math.max(v0.x, v1.x) + radius, math.max(v0.y, v1.y) + radius, math.max(v0.z, v1.z) + radius); }
Aabb3 extractAabbDisc(Vector3 v, double radius, Aabb3 out) #
Aabb3 extractAabbDisc(Vector3 v, double radius, Aabb3 out){ out.min.setValues(v.x - radius, v.y - radius, v.z - radius); out.max.setValues(v.x + radius, v.y + radius, v.z + radius); }
Vector3 extractCenter(List<Vector3> shape, Vector3 out) #
Vector3 extractCenter(List<Vector3> shape, Vector3 out) { out.x = 0.0; out.y = 0.0; for (int i = 0; i < shape.length; i++) { var v = shape[i]; out.x += v.x; out.y += v.y; } out.x /= shape.length; out.y /= shape.length; return out; }
Vector3 lookAt(Vector3 target, Vector3 position3d, Vector3 out, [Vector3 up]) #
return out
Vector3 lookAt(Vector3 target, Vector3 position3d, Vector3 out, [Vector3 up]) { up = (up == null) ? VY_AXIS : up; var m = makeViewMatrix(position3d, target, up).getRotation(); // code from (euler order XYZ) // https://github.com/mrdoob/three.js/blob/master/src/math/Vector3.js out.y = math.asin( clamp(m.row2.x, 1.0, -1.0 ) ); if ( m.row2.x.abs() < 0.99999 ) { out.x = math.atan2( - m.row2.y, m.row2.z ); out.z = math.atan2( - m.row1.x, m.row0.x ); } else { out.x = math.atan2( m.row1.z, m.row1.y ); out.z = 0.0; } return out; }
bool isSeparated(double minA, double maxA, double minB, double maxB) #
bool isSeparated( double minA, double maxA, double minB, double maxB ) { return (maxA < minB) || (maxB < minA); }