rhb-server/mes-ui/rhb-app/node_modules/gl-vec3/rotateZ.js
2025-10-20 11:14:41 +08:00

29 lines
644 B
JavaScript

module.exports = rotateZ;
/**
* Rotate a 3D vector around the z-axis
* @param {vec3} out The receiving vec3
* @param {vec3} a The vec3 point to rotate
* @param {vec3} b The origin of the rotation
* @param {Number} c The angle of rotation
* @returns {vec3} out
*/
function rotateZ(out, a, b, c){
var bx = b[0]
var by = b[1]
//Translate point to the origin
var px = a[0] - bx
var py = a[1] - by
var sc = Math.sin(c)
var cc = Math.cos(c)
// perform rotation and translate to correct position
out[0] = bx + px * cc - py * sc
out[1] = by + px * sc + py * cc
out[2] = a[2]
return out
}