mirror of
https://github.com/sbrl/Minetest-WorldEditAdditions.git
synced 2024-11-22 15:33:00 +00:00
comment
This commit is contained in:
parent
8372a12f48
commit
3e123ddc56
1 changed files with 18 additions and 15 deletions
33
rotate.js
33
rotate.js
|
@ -2,6 +2,9 @@
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Rotate a given point around an origin point in 3d space.
|
* Rotate a given point around an origin point in 3d space.
|
||||||
|
* NOTE: This function is not as intuitive as it sounds.
|
||||||
|
* A whiteboard and a head for mathematics is recommended before using this
|
||||||
|
* function.
|
||||||
* @source GitHub Copilot
|
* @source GitHub Copilot
|
||||||
* @warning Not completely tested! Pending a thorough evaluation.
|
* @warning Not completely tested! Pending a thorough evaluation.
|
||||||
* @param {Vector3} origin The origin point to rotate around
|
* @param {Vector3} origin The origin point to rotate around
|
||||||
|
@ -17,32 +20,32 @@ function rotate_point_3d(origin, point, x, y, z)
|
||||||
point[1] = point[1] - origin[1];
|
point[1] = point[1] - origin[1];
|
||||||
point[2] = point[2] - origin[2];
|
point[2] = point[2] - origin[2];
|
||||||
|
|
||||||
// rotate around x
|
// rotate around x
|
||||||
var x1 = point[0];
|
var x1 = point[0];
|
||||||
var y1 = point[1] * Math.cos(x) - point[2] * Math.sin(x);
|
var y1 = point[1] * Math.cos(x) - point[2] * Math.sin(x);
|
||||||
var z1 = point[1] * Math.sin(x) + point[2] * Math.cos(x);
|
var z1 = point[1] * Math.sin(x) + point[2] * Math.cos(x);
|
||||||
|
|
||||||
// rotate around y
|
// rotate around y
|
||||||
var x2 = x1 * Math.cos(y) + z1 * Math.sin(y);
|
var x2 = x1 * Math.cos(y) + z1 * Math.sin(y);
|
||||||
var y2 = y1;
|
var y2 = y1;
|
||||||
var z2 = -x1 * Math.sin(y) + z1 * Math.cos(y);
|
var z2 = -x1 * Math.sin(y) + z1 * Math.cos(y);
|
||||||
|
|
||||||
// rotate around z
|
// rotate around z
|
||||||
var x3 = x2 * Math.cos(z) - y2 * Math.sin(z);
|
var x3 = x2 * Math.cos(z) - y2 * Math.sin(z);
|
||||||
var y3 = x2 * Math.sin(z) + y2 * Math.cos(z);
|
var y3 = x2 * Math.sin(z) + y2 * Math.cos(z);
|
||||||
var z3 = z2;
|
var z3 = z2;
|
||||||
|
|
||||||
return [x3, y3, z3];
|
return [x3, y3, z3];
|
||||||
}
|
}
|
||||||
|
|
||||||
function deg_to_rad(deg)
|
function deg_to_rad(deg)
|
||||||
{
|
{
|
||||||
return deg * Math.PI / 180;
|
return deg * Math.PI / 180;
|
||||||
}
|
}
|
||||||
|
|
||||||
function point_to_string(point, decimal_places=3)
|
function point_to_string(point, decimal_places=3)
|
||||||
{
|
{
|
||||||
return "(x " + point[0].toFixed(decimal_places) + ", y " + point[1].toFixed(decimal_places) + ", z " + point[2].toFixed(decimal_places) + ")";
|
return "(x " + point[0].toFixed(decimal_places) + ", y " + point[1].toFixed(decimal_places) + ", z " + point[2].toFixed(decimal_places) + ")";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue