jsketcher/modules/brep/utils/vector-petrub.js
2022-08-15 23:47:20 -07:00

27 lines
409 B
JavaScript

export default function pertrub([x, y, z]) {
const s = x + y + z;
x = pertrubFloat(x + 3 + s);
y = pertrubFloat(y + 5 + s);
z = pertrubFloat(z + 7 + s);
const r = Math.sqrt(x*x + y*y + z*z);
return [
x/r,
y/r,
z/r
];
}
function pertrubFloat(x) {
return xorshift32(Math.round(x * 1e8)) ;
}
function xorshift32(x) {
x ^= x << 13;
x ^= x >> 17;
x ^= x << 5;
return x;
}