Update what's in global scope

This commit is contained in:
2024-02-25 23:31:48 +00:00
parent 9c8fe27ce4
commit 4351b4bf20
27 changed files with 634 additions and 777 deletions

View File

@@ -1,6 +1,8 @@
var Sphere = {};
Sphere.volume = function(r) { return Math.pi*r*r*r*4/3; };
Sphere.random = function(r,theta,phi)
var shape = {};
shape.sphere = {};
shape.circle = {};
shape.sphere.volume = function(r) { return Math.pi*r*r*r*4/3; };
shape.sphere.random = function(r,theta,phi)
{
if (typeof r === 'number') r = [r,r];
theta ??= [0,1];
@@ -18,9 +20,48 @@ Sphere.random = function(r,theta,phi)
];
}
var Circle = {};
Circle.area = function(r) { return Math.pi*r*r; };
Circle.random = function(r,theta)
shape.circle.area = function(r) { return Math.pi*r*r; };
shape.circle.random = function(r,theta)
{
return Sphere.random(r,theta).xz;
return shape.sphere.random(r,theta).xz;
}
shape.box = function(w,h) {
w /= 2;
h /= 2;
var points = [
[w,h],
[-w,h],
[-w,-h],
[w,-h]
];
return points;
};
shape.ngon = function(radius, n) {
return shape.arc(radius,360,n);
};
shape.arc = function(radius, angle, n, start) {
start ??= 0;
start = Math.deg2rad(start);
if (angle >= 360)
angle = 360;
if (n <= 1) return [];
var points = [];
angle = Math.deg2rad(angle);
var arclen = angle/n;
for (var i = 0; i < n; i++)
points.push(Vector.rotate([radius,0], start + (arclen*i)));
return points;
};
shape.circle.points = function(radius, n) {
if (n <= 1) return [];
return shape.arc(radius, 360, n);
};