primitives-3d_cone.js

import oc from "../opencascade/initializer";
import {Solid} from "../modeling";
import {Plane, Vector} from "../math";

/**
 * Creates a cone based on the specified parameters.
 * @memberof primitives-3D
 * @alias Cone
 * @param {Object} parameters - The parameters for the cone.
 * @param {Plane} [parameters.plane=Plane.XY] - The plane in which the cone is constructed.
 * @param {Vector} [parameters.center=Vector.ZERO] - The center of the cone.
 * @param {number} parameters.topRadius - The radius of the cone's top face.
 * @param {number} parameters.bottomRadius - The radius of the cone's bottom face.
 * @param {number} parameters.height - The height of the cone.
 * @returns {Solid} A `Solid` object representing the constructed cone.
 */
const Cone = ({plane = Plane.XY, center = Vector.ZERO, topRadius, bottomRadius, height}) => {
  const axis = plane.wrapped.Position().Ax2();
  const localOffset = plane.toWorldCoordinates(center.subtract(new Vector({z: height / 2})).wrapped);
  return new Solid(new oc.BRepPrimAPI_MakeCone_3(axis, bottomRadius, topRadius, height).Shape()).translate(
    new Vector({wrapped: localOffset})
  );
};

export {Cone};