cube([2,3,4]);
translate([3,0,0]) {
cube([2,3,4]);
}
Deno.writeTextFile("./sandbox.scad", sandbox().render())
export const hull = (...elements: OpenscadShape[]): OpenscadShape => {
return new OpenscadShape(
openScadFunctionCall({
name: "hull",
curlyBracesContent: elements.map((e) => e.build()).join("\n"),
})
);
};
const curlyBracesContentIndented = options.curlyBracesContent
? ` {${indent(options.curlyBracesContent)}}`
: ";";
return `${options.name} (${unnamedParamsString}${separator}${namedParamsString})${curlyBracesContentIndented}`;
hull(){
cube([0, 0, 0]);
cube([3, 0, 0]);
}
this.vertices = [
this.position.add(v3(-size.x / 2, -size.y / 2, -size.z / 2)),
this.position.add(v3(size.x / 2, -size.y / 2, -size.z / 2)),
this.position.add(v3(size.x / 2, size.y / 2, -size.z / 2)),
this.position.add(v3(-size.x / 2, size.y / 2, -size.z / 2)),
this.position.add(v3(-size.x / 2, -size.y / 2, size.z / 2)),
this.position.add(v3(size.x / 2, -size.y / 2, size.z / 2)),
this.position.add(v3(size.x / 2, size.y / 2, size.z / 2)),
this.position.add(v3(-size.x / 2, size.y / 2, size.z / 2)),
];
public translate = (delta: Vector3) => {
this.vertices = this.vertices.map((p) => p.add(delta));
this.position = this.position.add(delta);
return this;
};
export const rotatePoint = (options: RotatePointOptions): Vector3 => {
const initialVector = options.position.sub(options.origin);
const rotatedVector = { ...initialVector };
if (options.axis === Axis.Z) {
rotatedVector.x =
initialVector.x * Math.cos(-options.angleRadians) -
initialVector.y * Math.sin(-options.angleRadians);
rotatedVector.y =
initialVector.y * Math.cos(-options.angleRadians) +
initialVector.x * Math.sin(-options.angleRadians);
} else if (options.axis === Axis.X) {
rotatedVector.y =
initialVector.y * Math.cos(-options.angleRadians) -
initialVector.z * Math.sin(-options.angleRadians);
rotatedVector.z =
initialVector.z * Math.cos(-options.angleRadians) +
initialVector.y * Math.sin(-options.angleRadians);
} else if (options.axis === Axis.Y) {
rotatedVector.x =
initialVector.x * Math.cos(-options.angleRadians) -
initialVector.z * Math.sin(-options.angleRadians);
rotatedVector.z =
initialVector.z * Math.cos(-options.angleRadians) +
initialVector.x * Math.sin(-options.angleRadians);
}
return options.origin.add(rotatedVector);
};