Skip to content

Instantly share code, notes, and snippets.

@madhephaestus
Forked from jyxiao1/magazineDisplay.groovy
Created June 21, 2019 15:05
Show Gist options
  • Save madhephaestus/d2ad90e33e1049e64c5c605156427b48 to your computer and use it in GitHub Desktop.
Save madhephaestus/d2ad90e33e1049e64c5c605156427b48 to your computer and use it in GitHub Desktop.
3d model of a laser cutting template for a display
import java.lang.Math;
import eu.mihosoft.vrl.v3d.ext.quickhull3d.*
import eu.mihosoft.vrl.v3d.Vector3d
//Your code here
tierWidth = 145.625;
tierOverhang = 10;
tierThickness = 2;
tierHeight = 47.0202 + tierOverhang + tierThickness;
tierGap = 20;
sidePanelLength = 107.476205009;
CSG createFingerJoint(float startPoint, float endPoint, CSG objectToCut, CSG fingerJoint, String type){
float i = startPoint;
boolean cutJoint = true;
while(i < endPoint){
if(type == "x"){
fingerJoint = fingerJoint.movex(tierThickness);
}else if(type == "y"){
fingerJoint = fingerJoint.movey(tierThickness);
}else{
fingerJoint = fingerJoint.movez(tierThickness);
}
if(cutJoint){
objectToCut = objectToCut.difference(fingerJoint);
cutJoint = false;
}else{
cutJoint = true;
}
i += tierThickness;
}
return objectToCut;
}
//Bridge size goes from 14mm to 23mm
//We go for a medium around 18mm
CSG tierBack = new Cube(tierWidth,// X dimention
tierHeight,// Y dimention
tierThickness// Z dimention
).toCSG()// this converts from the geometry to an object we can work with
CSG tierPerpendicular = new Cube(tierWidth + 2 * tierThickness,// X dimention
tierGap,// Y dimention
tierThickness// Z dimention
).toCSG()// this converts from the geometry to an object we can work with
CSG myJoint = new Cube(tierThickness,// X dimention
tierThickness,// Y dimention
tierThickness// Z dimention
).toCSG()// this converts from the geometry to an object we can work with
myJoint = myJoint.movex(-(tierWidth / 2 + tierThickness / 2))
.movey(-tierGap / 2 + tierThickness / 2);
tierPerpendicular = createFingerJoint((-tierGap / 2), (tierGap / 2), tierPerpendicular, myJoint, "y");
myJoint = new Cube(tierThickness,// X dimention
tierThickness,// Y dimention
tierThickness// Z dimention
).toCSG()// this converts from the geometry to an object we can work with
myJoint = myJoint.movex((tierWidth / 2 + tierThickness / 2))
.movey(-tierGap / 2 + tierThickness / 2);
tierPerpendicular = createFingerJoint((-tierGap / 2), (tierGap / 2), tierPerpendicular, myJoint, "y");
tierPerpendicular = tierPerpendicular.setName("lastTierPerpendicular");
tierPerpendicular = tierPerpendicular.rotx(90);
tierPerpendicular = tierPerpendicular.movey(tierHeight / 2 - tierThickness / 2);
tierPerpendicular = tierPerpendicular.movez(tierGap / 2 - tierThickness / 2);
myJoint = new Cube(tierThickness,// X dimention
tierThickness,// Y dimention
tierThickness// Z dimention
).toCSG();// this converts from the geometry to an object we can work with
myJoint = myJoint.movex(-tierWidth / 2 + tierThickness / 2)
.movey(tierHeight / 2 - tierThickness / 2);
tierBack = createFingerJoint((-tierWidth / 2), (tierWidth / 2), tierBack, myJoint, "x");
myJoint = myJoint.movex(tierWidth / 2 - tierThickness / 2)
.movey(-tierHeight / 2 + tierThickness / 2);
tierBack.setName("tierBack");
//tierPerpendicular = tierPerpendicular.difference(tierBack);
tier1 = tierBack;
tierBack1 = tierPerpendicular;
tier2 = tier1.movez(tierGap - tierThickness);
tier2 = tier2.movey(tierHeight - tierThickness - tierOverhang);
tierBack2 = tierBack1.movez(tierGap - tierThickness);
tierBack2 = tierBack2.movey(tierHeight - tierThickness - tierOverhang);
tier3 = tier2.movez(tierGap - tierThickness);
tier3 = tier3.movey(tierHeight - tierThickness - tierOverhang);
tierBack3 = tierBack2.movez(tierGap - tierThickness);
tierBack3 = tierBack3.movey(tierHeight - tierThickness - tierOverhang);
lastTierOverhang = new Cube(tierWidth,// X dimention
tierOverhang + tierThickness,// Y dimention
tierThickness// Z dimention
).toCSG();// this converts from the geometry to an object we can work with
lastTierOverhang = lastTierOverhang.movey((tierHeight - tierOverhang) / 2 - tierThickness / 2)
lastTierOverhang = lastTierOverhang.movez(tierGap - tierThickness);
lastTierOverhang = lastTierOverhang.movey(2*(tierHeight - tierThickness - tierOverhang));
lastTierOverhang = lastTierOverhang.movez(2*(tierGap - tierThickness));
tiers = [tier1, tierBack1, tier2, tierBack2, tier3, tierBack3, lastTierOverhang];
for(CSG item : tiers){
item = item.rotx(60);
item = item.movez(150 - (tierHeight * (Math.pow(3,0.5) / 2) + tierThickness / 2) / 2);
item = item.movey(tierHeight / 2 / 2 + tierThickness * Math.pow(3,0.5) / 2 / 2);
}
for(i = 0; i < tiers.size(); i++){
tiers[i] = tiers[i].rotx(60);
tiers[i] = tiers[i].movez(150 - (tierHeight * (Math.pow(3,0.5) / 2) + tierThickness / 2) / 2);
tiers[i] = tiers[i].movey(tierHeight / 2 / 2 + tierThickness * Math.pow(3,0.5) / 2 / 2);
}
bottomPanel = new Cube(tierWidth,// X dimention
sidePanelLength,// Y dimention
tierThickness// Z dimention
).toCSG()// this converts from the geometry to an object we can work with
myJoint = new Cube(tierThickness,// X dimention
tierThickness,// Y dimention
tierThickness// Z dimention
).toCSG()// this converts from the geometry to an object we can work with
myJoint = myJoint.movex(-tierWidth / 2 + tierThickness / 2)
.movey(-(sidePanelLength) / 2 + tierThickness / 2);
float moveFingerJointVal = (sidePanelLength) / 2;
bottomPanel = createFingerJoint(-moveFingerJointVal, moveFingerJointVal, bottomPanel, myJoint, "y");
myJoint = myJoint.movey(tierThickness * 48);
bottomPanel = bottomPanel.difference(myJoint);
myJoint = new Cube(tierThickness,// X dimention
tierThickness,// Y dimention
tierThickness// Z dimention
).toCSG()// this converts from the geometry to an object we can work with
myJoint = myJoint.movex(tierWidth / 2 - tierThickness / 2)
.movey(-(sidePanelLength) / 2 + tierThickness / 2);
bottomPanel = createFingerJoint(-moveFingerJointVal, moveFingerJointVal, bottomPanel, myJoint, "y");
myJoint = myJoint.movey(tierThickness * 48);
bottomPanel = bottomPanel.difference(myJoint);
myJoint = new Cube(tierThickness,// X dimention
tierThickness,// Y dimention
tierThickness// Z dimention
).toCSG()// this converts from the geometry to an object we can work with
myJoint = myJoint.movex(-tierWidth / 2 + tierThickness / 2 - tierThickness / 4)
.movey((sidePanelLength) / 2 - tierThickness / 2);
moveFingerJointVal = tierWidth / 2;
float val1 = -moveFingerJointVal;// + tierThickness;
float val2 = moveFingerJointVal;// - 5 * tierThickness;
bottomPanel = createFingerJoint(val1, val2, bottomPanel, myJoint, "x");
//return [myJoint, bottomPanel];
bottomPanel = bottomPanel.movey(sidePanelLength / 2);
//myJoint = fingerJoint = fingerJoint.movex(tierThickness);
//myJoint = myJoint.movex(-tierWidth / 2 + tierThickness / 2)
// .movey(sidePanelLength - tierThickness / 2);
//bottomPanel = createFingerJoint(-tierWidth / 2, tierWidth / 2, bottomPanel, myJoint, "x");
//bottomPanel = bottomPanel.movez(tierThickness / 2);
//bottomPanel = bottomPanel.setName("bottomPanel1");
//return bottomPanel;
firstShelf = bottomPanel.movez((tierHeight - tierThickness - tierOverhang) * Math.pow(3,0.5) / 2 - (tierGap - tierThickness) / 2);
shelfShrinkAmount = 1 / 2 * (tierHeight - tierThickness - tierOverhang) + Math.pow(3,0.5) / 2 * (tierGap - tierThickness);
secondShelf = new Cube(tierWidth,// X dimention
sidePanelLength - shelfShrinkAmount,// Y dimention
tierThickness// Z dimention
).toCSG()// this converts from the geometry to an object we can work with
myJoint = new Cube(tierThickness,// X dimention
tierThickness,// Y dimention
tierThickness// Z dimention
).toCSG()// this converts from the geometry to an object we can work with
myJoint = myJoint.movex(-tierWidth / 2 + tierThickness / 2)
.movey(-(sidePanelLength - shelfShrinkAmount) / 2 + tierThickness / 2);
moveFingerJointVal = (sidePanelLength - shelfShrinkAmount) / 2;
secondShelf = createFingerJoint(-moveFingerJointVal, moveFingerJointVal, secondShelf, myJoint, "y");
myJoint = new Cube(tierThickness,// X dimention
tierThickness,// Y dimention
tierThickness// Z dimention
).toCSG()// this converts from the geometry to an object we can work with
myJoint = myJoint.movex(tierWidth / 2 - tierThickness / 2)
.movey(-(sidePanelLength - shelfShrinkAmount) / 2 + tierThickness / 2);
secondShelf = createFingerJoint(-moveFingerJointVal, moveFingerJointVal, secondShelf, myJoint, "y");
secondShelf = secondShelf.movey((sidePanelLength - 1 / 2 * (tierHeight - tierThickness - tierOverhang) - Math.pow(3,0.5) / 2 * (tierGap - tierThickness)) / 2);
secondShelf = secondShelf.movez(tierThickness / 2);
secondShelf = secondShelf.movez((tierHeight - tierThickness - tierOverhang) * Math.pow(3,0.5) / 2 - (tierGap - tierThickness) / 2);
secondShelf = secondShelf.movez((tierHeight - tierThickness - tierOverhang) * Math.pow(3,0.5) / 2 - (tierGap - tierThickness) / 2);
thirdShelf = new Cube(tierWidth,// X dimention
sidePanelLength - 1 / 2 * (tierHeight - tierThickness - tierOverhang) - Math.pow(3,0.5) / 2 * (tierGap - tierThickness) - 1 / 2 * (tierHeight - tierThickness - tierOverhang) - Math.pow(3,0.5) / 2 * (tierGap - tierThickness),// Y dimention
tierThickness// Z dimention
).toCSG()// this converts from the geometry to an object we can work with
myJoint = new Cube(tierThickness,// X dimention
tierThickness,// Y dimention
tierThickness// Z dimention
).toCSG()// this converts from the geometry to an object we can work with
myJoint = myJoint.movex(tierWidth / 2 - tierThickness / 2)
.movey(-(sidePanelLength - 2 * shelfShrinkAmount) / 2 + tierThickness / 2);
moveFingerJointVal = (sidePanelLength - 2 * shelfShrinkAmount) / 2;
thirdShelf = createFingerJoint(-moveFingerJointVal, moveFingerJointVal, thirdShelf, myJoint, "y");
myJoint = new Cube(tierThickness,// X dimention
tierThickness,// Y dimention
tierThickness// Z dimention
).toCSG()// this converts from the geometry to an object we can work with
myJoint = myJoint.movex(-tierWidth / 2 + tierThickness / 2)
.movey(-(sidePanelLength - 2 * shelfShrinkAmount) / 2 + tierThickness / 2);
thirdShelf = createFingerJoint(-moveFingerJointVal, moveFingerJointVal, thirdShelf, myJoint, "y");
thirdShelf = thirdShelf.movey((sidePanelLength - 1 / 2 * (tierHeight - tierThickness - tierOverhang) - Math.pow(3,0.5) / 2 * (tierGap - tierThickness) - 1 / 2 * (tierHeight - tierThickness - tierOverhang)- Math.pow(3,0.5) / 2 * (tierGap - tierThickness)) / 2);
thirdShelf = thirdShelf.movez(tierThickness / 2);
thirdShelf = thirdShelf.movez((tierHeight - tierThickness - tierOverhang) * Math.pow(3,0.5) / 2 - (tierGap - tierThickness) / 2);
thirdShelf = thirdShelf.movez((tierHeight - tierThickness - tierOverhang) * Math.pow(3,0.5) / 2 - (tierGap - tierThickness) / 2);
thirdShelf = thirdShelf.movez((tierHeight - tierThickness - tierOverhang) * Math.pow(3,0.5) / 2 - (tierGap - tierThickness) / 2);
frontPanel = new Cube(tierWidth - tierThickness * 2,// X dimention
tierThickness,// Y dimention
((tierHeight - tierThickness - tierOverhang) * Math.pow(3,0.5) / 2 - (tierGap - tierThickness) / 2 + tierThickness)// Z dimention
).toCSG()// this converts from the geometry to an object we can work with
frontPanel = frontPanel.movez(((tierHeight - tierThickness - tierOverhang) * Math.pow(3,0.5) / 2 - (tierGap - tierThickness) / 2 + tierThickness) / 2);
frontPanel = frontPanel.movey(sidePanelLength - tierThickness/2);
frontPanel = frontPanel.difference(bottomPanel);
frontPanel = frontPanel.difference(firstShelf);
//frontPanel = frontPanel.rotx(90);
//frontPanel = frontPanel.movez(106);
frontPanel = frontPanel.setName("frontPanel");
//return frontPanel;
// points are given in order from top to bottom
firstPointX = 0;
firstPointY = 150 - 1/2 * tierThickness;
secondPointX = firstPointX + 1/2 * tierHeight;
secondPointY = firstPointY - Math.pow(3,0.5) / 2 * tierHeight;
thirdPointX = secondPointX + Math.pow(3,0.5) / 2 * (tierGap - tierThickness);
thirdPointY = secondPointY + 1 / 2 * (tierGap - tierThickness);
fourthPointX = thirdPointX + 1 / 2 * (tierHeight - tierOverhang - tierThickness);
fourthPointY = thirdPointY - Math.pow(3,0.5) / 2 * (tierHeight - tierOverhang - tierThickness);
fifthPointX = fourthPointX + Math.pow(3,0.5) / 2 * (tierGap - tierThickness);
fifthPointY = fourthPointY + 1 / 2 * (tierGap - tierThickness);
sixthPointX = fifthPointX + 1/2 * (tierHeight - tierOverhang - tierThickness);
sixthPointY = fifthPointY - Math.pow(3,0.5) / 2 * (tierHeight - tierOverhang - tierThickness);
seventhPointX = sixthPointX;
seventhPointY = 0;
eighthPointX = 0;
eighthPointY = 0;
def sidePanelPoints = [new Vector3d(firstPointX, firstPointY, 0),
new Vector3d(secondPointX, secondPointY, 0),
new Vector3d(thirdPointX, thirdPointY, 0),
new Vector3d(fourthPointX, fourthPointY, 0),
new Vector3d(fifthPointX, fifthPointY, 0),
new Vector3d(sixthPointX, sixthPointY, 0),
new Vector3d(seventhPointX, seventhPointY, 0),
new Vector3d(eighthPointX, eighthPointY, 0),
new Vector3d(firstPointX, firstPointY, 0)];
CSG sidePanel = Extrude.points(new Vector3d(0, 0, tierThickness),
new Vector3d(firstPointX, firstPointY, 0),
new Vector3d(secondPointX, secondPointY, 0),
new Vector3d(thirdPointX, thirdPointY, 0),
new Vector3d(fourthPointX, fourthPointY, 0),
new Vector3d(fifthPointX, fifthPointY, 0),
new Vector3d(sixthPointX, sixthPointY, 0),
new Vector3d(seventhPointX, seventhPointY, 0),
new Vector3d(eighthPointX, eighthPointY, 0)
);
sidePanel = sidePanel.roty(-90).rotx(-90);
innerLeftSidePanel = sidePanel.movex(tierWidth / 2 - tierThickness);
innerLeftSidePanel = innerLeftSidePanel.difference(bottomPanel);
innerLeftSidePanel = innerLeftSidePanel.difference(firstShelf);
innerLeftSidePanel = innerLeftSidePanel.difference(secondShelf);
innerLeftSidePanel = innerLeftSidePanel.difference(thirdShelf);
innerLeftSidePanel = innerLeftSidePanel.setName("innerSidePanel");
innerRightSidePanel = sidePanel.movex(-tierWidth / 2);
innerLeftSidePanel = innerLeftSidePanel.difference(bottomPanel);
innerLeftSidePanel = innerLeftSidePanel.difference(firstShelf);
innerRightSidePanel = innerRightSidePanel.difference(secondShelf);
innerRightSidePanel = innerRightSidePanel.difference(thirdShelf);
eighthPointX = sixthPointX;
eighthPointY = sixthPointY;
ninthPointX = seventhPointX;
ninthPointY = 0;
tenthPointX = 0;
tenthPointY = 0;
secondPointX = firstPointX + Math.pow(3,0.5) / 2 * tierGap;
secondPointY = firstPointY + 1 / 2 * tierGap;
thirdPointX = secondPointX + 1 / 2 * (tierHeight - tierOverhang - tierThickness);
thirdPointY = secondPointY - Math.pow(3,0.5) / 2 * (tierHeight - tierOverhang - tierThickness);
fourthPointX = thirdPointX + Math.pow(3,0.5) / 2 * (tierGap - tierThickness);
fourthPointY = thirdPointY + 1 / 2 * (tierGap - tierThickness);
fifthPointX = fourthPointX + 1 / 2 * (tierHeight - tierOverhang - tierThickness);
fifthPointY = fourthPointY - Math.pow(3,0.5) / 2 * (tierHeight - tierOverhang - tierThickness);
sixthPointX = fifthPointX + Math.pow(3,0.5) / 2 * (tierGap - tierThickness);
sixthPointY = fifthPointY + 1 / 2 * (tierGap - tierThickness);
seventhPointX = sixthPointX + 1 / 2 * (tierHeight);
seventhPointY = sixthPointY - Math.pow(3,0.5) / 2 * (tierHeight);
CSG outerSidePanel = Extrude.points(new Vector3d(0, 0, tierThickness),
new Vector3d(firstPointX, firstPointY, 0),
new Vector3d(secondPointX, secondPointY, 0),
new Vector3d(thirdPointX, thirdPointY, 0),
new Vector3d(fourthPointX, fourthPointY, 0),
new Vector3d(fifthPointX, fifthPointY, 0),
new Vector3d(sixthPointX, sixthPointY, 0),
new Vector3d(seventhPointX, seventhPointY, 0),
new Vector3d(eighthPointX, eighthPointY, 0),
new Vector3d(ninthPointX, ninthPointY, 0),
new Vector3d(tenthPointX, tenthPointY, 0)
);
outerSidePanel = outerSidePanel.roty(-90).rotx(-90);
outerLeftSidePanel = outerSidePanel.movex(tierWidth / 2);
outerRightSidePanel = outerSidePanel.movex(-tierWidth / 2 - tierThickness);
outerRightSidePanel = outerRightSidePanel.difference(tiers[5]);
outerRightSidePanel = outerRightSidePanel.setName("outerRightDiff");
outerSidePanel = outerSidePanel.setName("outerSidePanel");
display = CSG.unionAll([tiers[0], tiers[1], tiers[2], tiers[3], tiers[4], tiers[5], tiers[6], frontPanel, bottomPanel, firstShelf, secondShelf, thirdShelf, innerLeftSidePanel, innerRightSidePanel, outerLeftSidePanel, outerRightSidePanel]);
display = display.setName("conventionBookshelfDisplay");
//thirdShelf = thirdShelf.setName("thirdShelf");
//return thirdShelf;
wtierPerpendicular = tierPerpendicular.rotx(90).movez(28);
//return tierPerpendicular;
return [tiers[0], tiers[1], tiers[2], tiers[3], tiers[4], tiers[5], tiers[6], frontPanel, bottomPanel, firstShelf, secondShelf, thirdShelf, innerLeftSidePanel, innerRightSidePanel, outerLeftSidePanel, outerRightSidePanel];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment