SUMCON
3D Graphics Package

Module

3D Graphics Generation

Generate a closed cuboid

shp$myCuboid[{x_,y_,z_},{dx_,dy_,dz_}]:=
{
Polygon[
{
{x-dx/2,y+dy/2,z-dz/2},{x-dx/2,y+dy/2,z+dz/2},
{x-dx/2,y-dy/2,z+dz/2},{x-dx/2,y-dy/2,z-dz/2}
}
],
Polygon[
{
{x+dx/2,y+dy/2,z-dz/2},{x+dx/2,y+dy/2,z+dz/2},
{x+dx/2,y-dy/2,z+dz/2},{x+dx/2,y-dy/2,z-dz/2}
}
],
Polygon[
{
{x-dx/2,y-dy/2,z-dz/2},{x-dx/2,y+dy/2,z-dz/2},
{x+dx/2,y+dy/2,z-dz/2},{x+dx/2,y-dy/2,z-dz/2}
}
],
Polygon[
{
{x-dx/2,y-dy/2,z+dz/2},{x-dx/2,y+dy/2,z+dz/2},
{x+dx/2,y+dy/2,z+dz/2},{x+dx/2,y-dy/2,z+dz/2}
}
],
Polygon[
{
{x-dx/2,y-dy/2,z-dz/2},{x-dx/2,y-dy/2,z+dz/2},
{x+dx/2,y-dy/2,z+dz/2},{x+dx/2,y-dy/2,z-dz/2}
}
],
Polygon[
{
{x-dx/2,y+dy/2,z-dz/2},{x-dx/2,y+dy/2,z+dz/2},
{x+dx/2,y+dy/2,z+dz/2},{x+dx/2,y+dy/2,z-dz/2}
}
]
};

Generate an open cuboid (y-oriented)

shp$myOpenCuboid[{x_,y_,z_},{dx_,dy_,dz_}]:=
{
Polygon[
{
{x-dx/2,y+dy/2,z-dz/2},{x-dx/2,y+dy/2,z+dz/2},
{x-dx/2,y-dy/2,z+dz/2},{x-dx/2,y-dy/2,z-dz/2}
}
],
Polygon[
{
{x+dx/2,y+dy/2,z-dz/2},{x+dx/2,y+dy/2,z+dz/2},
{x+dx/2,y-dy/2,z+dz/2},{x+dx/2,y-dy/2,z-dz/2}
}
],
Polygon[
{
{x-dx/2,y-dy/2,z-dz/2},{x-dx/2,y+dy/2,z-dz/2},
{x+dx/2,y+dy/2,z-dz/2},{x+dx/2,y-dy/2,z-dz/2}
}
],
Polygon[
{
{x-dx/2,y-dy/2,z+dz/2},{x-dx/2,y+dy/2,z+dz/2},
{x+dx/2,y+dy/2,z+dz/2},{x+dx/2,y-dy/2,z+dz/2}
}
]
};

Generate an open cylinder (y-oriented)

shp$myCylinderY[{x_,y_,z_},{d_, l_}] :=
Module[{rc1,rs1,rc2,rs2},
Table[
rc1= N[d*Cos[2Pi i/20]]/2; rs1= N[d*Sin[2Pi i/20]]/2;
rc2= N[d* Cos[2Pi (i+1)/20]]/2; rs2= N[d*Sin[2Pi (i+1)/20]]/2;
{If[MemberQ[{4,5,9,10,14,15,19,20},i],Red,Blue],
	Polygon[
{{x+rc1, y+l/2, z+rs1},{x+rc1,y-l/2,z+ rs1},
{x+rc2, y-l/2, z+rs2},{x+rc2,y+l/2,z+ rs2} }
]}, {i,20}
]
];

Generate an open cylinder (z-oriented)

shp$myCylinderZ[{x_,y_,z_},{d_, l_}] :=
Module[{rc1,rs1,rc2,rs2},
Table[
rc1= N[d*Cos[2Pi i/20]]/2; rs1= N[d*Sin[2Pi i/20]]/2;
rc2= N[d*Cos[2Pi (i+1)/20]]/2; rs2= N[d*Sin[2Pi (i+1)/20]]/2;
	{If[MemberQ[{4,5,9,10,14,15,19,20},i],Red,Blue],
Polygon[
{{x+rc1, y+rs1, z+l/2},{x+rc1,y+ rs1,z-l/2},
{x+rc2, y+rs2, z-l/2},{x+rc2,y+ rs2,z+l/2} }
]}, {i,20}
]
];

Generate an open truncated cone (y-oriented)

shp$myTruncatedCone[{x_,y_,z_},{du_,dl_, l_}] :=
Module[{ruc1,rus1,ruc2,rus2,rlc1,rls1,rlc2,rls2},
Table[
ruc1= N[du Cos[2Pi i/20]]/2; rus1= N[du Sin[2Pi i/20]]/2;
ruc2= N[du Cos[2Pi (i+1)/20]]/2; rus2= N[du Sin[2Pi (i+1)/20]]/2;
rlc1= N[dl Cos[2Pi i/20]]/2; rls1= N[dl Sin[2Pi i/20]]/2;
rlc2= N[dl Cos[2Pi (i+1)/20]]/2; rls2= N[dl Sin[2Pi (i+1)/20]]/2;
{If[MemberQ[{4,5,9,10,14,15,19,20},i],Red,Blue],
	Polygon[
{{x+ruc1, y+l/2, z+rus1},{x+rlc1,y-l/2,z+ rls1},
{x+rlc2, y-l/2, z+rls2},{x+ruc2,y+l/2,z+ rus2} }
]}, {i,20}
]
];

Generate an open double cylinder (y-oriented)

shp$myDoubleCylinder[{x_,y_,z_},{du_,dl_,hu_,hl_,hc_}] :=
Module[{rc1,rs1,rc2,rs2},
Join[
Table[
rc1= N[du Cos[2Pi i/20]]/2; rs1= N[du Sin[2Pi i/20]]/2;
rc2= N[du Cos[2Pi (i+1)/20]]/2; rs2= N[du Sin[2Pi (i+1)/20]]/2;
{If[MemberQ[{4,5,9,10,14,15,19,20},i],Red,Blue],
	Polygon[
{{x+rc1, y+hu+hl-hc, z+rs1},{x+rc1,y+hl-hc,z+ rs1},
{x+rc2, y+hl-hc, z+rs2},{x+rc2,y+hu+hl-hc,z+ rs2} }
]}, {i,20}
],
Table[
{If[MemberQ[{4,5,9,10,14,15,19,20},i],Red,Blue],
rc1= N[dl Cos[2Pi i/20]/2]; rs1= N[dl Sin[2Pi i/20]/2];
rc2= N[dl Cos[2Pi (i+1)/20]/2]; rs2= N[dl Sin[2Pi (i+1)/20]/2];
	Polygon[
{{x+rc1, y+hl-hc, z+rs1},{x+rc1,y-hc,z+ rs1},
{x+rc2, y-hc, z+rs2},{x+rc2,y+hl-hc,z+ rs2} }
]}, {i,20}
]
]
];

Generate a horizontal doughnut-circle

shp$myDoughnut[{x_,y_,z_},{do_,di_}] :=
Module[{ric1,ris1,ric2,ris2,roc1,ros1,roc2,ros2},
Table[
ric1= N[di Cos[2Pi i/20]/2]; ris1= N[di Sin[2Pi i/20]/2];
ric2= N[di Cos[2Pi (i+1)/20]/2]; ris2= N[di Sin[2Pi (i+1)/20]/2];
roc1= N[do Cos[2Pi i/20]/2]; ros1= N[do Sin[2Pi i/20]/2];
roc2= N[do Cos[2Pi (i+1)/20]/2]; ros2= N[do Sin[2Pi (i+1)/20]/2];
	Polygon[
{{x+roc1, y, z+ros1},{x+ric1,y,z+ ris1},
{x+ric2, y, z+ris2},{x+roc2,y,z+ ros2} }
], {i,20}
]
];

Generate a horizontal circle

shp$myCircle[{x_,y_,z_},{d_}] :=
Module[{rc1,rs1,rc2,rs2},
Table[
rc1= N[d*Cos[2Pi i/20]/2]; rs1= N[d*Sin[2Pi i/20]/2];
rc2= N[d*Cos[2Pi (i+1)/20]/2]; rs2= N[d*Sin[2Pi (i+1)/20]/2];
	Polygon[
{{x+rc1, y, z+rs1},{x+rc2,y,z+ rs2},{x, y, z}}
], {i,20}
]
];

Create 3D shapes

mod$Create3DShape[r0_,shp_,dim_]:=
Which[
shp=="Cuboid",shp$myCuboid[r0,dim[[1;;3]]],
shp=="OpenCuboid[y]",shp$myOpenCuboid[r0,dim[[1;;3]]],
shp=="Cylinder[y]",shp$myCylinderY[r0,dim[[1;;2]]],
shp=="Cylinder[z]",shp$myCylinderZ[r0,dim[[1;;2]]],
shp=="TruncatedCone[y]",shp$myTruncatedCone[r0,dim[[1;;3]]],
shp=="DoubleCylinder[y]",shp$myDoubleCylinder[r0,dim[[1;;5]]],
shp=="Doughnut[y]",shp$myDoughnut[r0,dim[[1;;2]]],
shp=="Circle[y]",shp$myCircle[r0,dim[[1;;1]]]
];

mod$Create3DShape::usage=
"mod$Create3DShape[r0, shp,dim] generates 3D graphics with given shape 'shp' and corresponding dimension 'dim' at the position vector 'r0'. The shape should be chose from list$BodyShape.";

Body Shape List

list$BodyShape={
"Cuboid",
"OpenCuboid[y]",
"Cylinder[y]",
"Cylinder[z]",
"TruncatedCone[y]",
"DoubleCylinder[y]",
"Doughnut[y]",
"Circle[y]"
};

list$ShapeDimNote[shp_]:=Which[
shp=="Cuboid",
{"X-Size","Y-Size","Z-Size","",""},
shp=="OpenCuboid[y]",
{"X-Size","Y-Size","Z-Size","",""},
shp=="Cylinder[y]",
{"Diameter","Height","","",""},
shp=="Cylinder[z]",
{"Diameter","Length","","",""},
shp=="TruncatedCone[y]",
{"Upper D","Lower D","Height","",""},
shp=="DoubleCylinder[y]",
{"Upper D","Lower D","Upper H","Lower H","CoM Height"},
shp=="Doughnut[y]",
{"Outer D", "Inner D","","",""},
shp=="Circle[y]",
{"Diamteter","","","",""}
];