/
rotateBy.js
39 lines (36 loc) · 1 KB
/
rotateBy.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// @affineplane.plane3.rotateBy(plane, center, radians)
//
// Rotate the given plane in the reference space around
// a line parallel to z-axis and which goes through
// the given center point. The plane z depth is preserved.
//
// Parameter
// plane
// a plane3 in the reference space.
// .. The plane to rotate.
// center
// a point3, a point in the reference space.
// .. Defines the line around which to rotate.
// radians
// a number, angle in radians, direction x -> y.
//
// Return
// a plane3 on the reference plane after rotation.
//
module.exports = function (plane, center, radians) {
const co = Math.cos(radians)
const si = Math.sin(radians)
const cx = center.x
const cy = center.y
const ahat = plane.a * co - plane.b * si
const bhat = plane.a * si + plane.b * co
const xhat = (plane.x - cx) * co - (plane.y - cy) * si + cx
const yhat = (plane.x - cx) * si + (plane.y - cy) * co + cy
return {
a: ahat,
b: bhat,
x: xhat,
y: yhat,
z: plane.z
}
}