primitives-2d_regular-polygon.js
import {Polygon} from "./index";
import {Plane, Vector} from "../math";
/**
* Creates a regular polygon based on the specified parameters.
* @memberof primitives-2D
* @alias RegularPolygon
* @param {Object} parameters - The parameters for the regular polygon.
* @param {Plane} [parameters.plane=Plane.XY] - The plane in which the polygon is constructed.
* @param {Vector} [parameters.center=Vector.ZERO] - The center of the polygon.
* @param {number} parameters.radius - The radius of the circumscribed circle of the polygon.
* @param {number} parameters.vertices - The number of vertices of the polygon.
* @returns {Face} A `Face` object representing the constructed regular polygon.
*/
const RegularPolygon = ({plane = Plane.XY, center = Vector.ZERO, radius, vertices}) => {
const points = [];
const angle = (2 * Math.PI) / vertices;
for (let i = 0; i < vertices; i++) {
points.push(
new Vector({
x: center.x + radius * Math.sin(i * angle),
y: center.y + radius * Math.cos(i * angle),
z: center.z,
})
);
}
return Polygon({
plane: plane,
vertices: points.reverse(),
});
};
export {RegularPolygon};