Browse Source

math lib tweaks

Alexander Rose 5 years ago
parent
commit
06354d6d1d

+ 3 - 0
src/mol-math/linear-algebra/3d/mat4.ts

@@ -1021,6 +1021,9 @@ namespace Mat4 {
     export const rotZ90X180: ReadonlyMat4 = Mat4.mul(Mat4(), rotZ90, rotX180)
     /** Rotation matrix for 90deg around first y-axis and then 180deg around z-axis */
     export const rotY90Z180: ReadonlyMat4 = Mat4.mul(Mat4(), rotY90, rotZ180)
+
+    /** Identity matrix */
+    export const id: ReadonlyMat4 = Mat4.identity()
 }
 
 export default Mat4

+ 1 - 1
src/mol-math/linear-algebra/3d/vec3.ts

@@ -513,8 +513,8 @@ namespace Vec3 {
         return v[0] === 0 && v[1] === 0 && v[2] === 0;
     }
 
+    /** Project `point` onto `vector` starting from `origin` */
     export function projectPointOnVector(out: Vec3, point: Vec3, vector: Vec3, origin: Vec3) {
-        // point.sub(origin).projectOnVector(vector).add(origin)
         sub(out, copy(out, point), origin)
         const scalar = dot(vector, out) / squaredMagnitude(vector);
         return add(out, scale(out, copy(out, vector), scalar), origin);

+ 7 - 0
src/mol-math/misc.ts

@@ -4,6 +4,8 @@
  * @author Alexander Rose <alexander.rose@weirdbyte.de>
  */
 
+export const halfPI = Math.PI / 2
+
 export function degToRad (deg: number) {
     return deg * 0.01745  // deg * Math.PI / 180
 }
@@ -29,4 +31,9 @@ export function absMax(...values: number[]) {
         }
     }
     return max
+}
+
+/** Length of an arc with angle in radians */
+export function arcLength(angle: number, radius: number) {
+    return angle * radius
 }