//make a rounded 6 sided polyhedra, basically just a box with the corners moved //"boxoid" is the wrong term... because it's been too long since I did my maths degree... // //RoundedBoxoid( rounding, boxPoints ) //rounding = amount to expand the boxoid by with rounding //boxPoints = array of 8 corner points. they must describe co-planar 4-pointed faces, otherwise you're screwed. //order of points is: ---, --+, -+-, -++, +--, +-+, ++-, +++ or any transposed equivalent to that. #macro face(p0,p1,p2,p3,ni) //make a face of the rounded shape, by pushing faces out in direction of their normal. //points must be in clockwise order as seen from outside the box #declare n[ni] = rounding * vnormalize(vcross(p1 - p0,p2 - p0)); //polygon { 4, p0+n, p1+n, p2+n, p3+n } triangle { p0+n[ni], p1+n[ni], p2+n[ni] } triangle { p0+n[ni], p2+n[ni], p3+n[ni] } #end #macro edge_poly(p0,p1,na,nb) //make a poly to fill the gaps. triangle { p0+na, p1+na, p1+nb } triangle { p0+na, p1+nb, p0+nb } #end #macro corner_poly(p,na,nb,nc) //trivial triangle { p+na, p+nb, p+nc } #end #macro RoundedBoxoid( rounding, boxPoints ) merge { mesh { //use a mesh so we can use CSG inside_vector x #declare n = array[6]; //the six sides face( boxPoints[2], boxPoints[3], boxPoints[1], boxPoints[0], 0 ) face( boxPoints[4], boxPoints[5], boxPoints[7], boxPoints[6], 1 ) face( boxPoints[0], boxPoints[1], boxPoints[5], boxPoints[4], 2 ) face( boxPoints[6], boxPoints[7], boxPoints[3], boxPoints[2], 3 ) face( boxPoints[4], boxPoints[6], boxPoints[2], boxPoints[0], 4 ) face( boxPoints[1], boxPoints[3], boxPoints[7], boxPoints[5], 5 ) //close up the gaps edge_poly( boxPoints[0], boxPoints[1], n[2], n[0] ) edge_poly( boxPoints[2], boxPoints[3], n[0], n[3] ) edge_poly( boxPoints[4], boxPoints[5], n[1], n[2] ) edge_poly( boxPoints[6], boxPoints[7], n[3], n[1] ) edge_poly( boxPoints[0], boxPoints[2], n[0], n[4] ) edge_poly( boxPoints[1], boxPoints[3], n[5], n[0] ) edge_poly( boxPoints[4], boxPoints[6], n[4], n[1] ) edge_poly( boxPoints[5], boxPoints[7], n[1], n[5] ) edge_poly( boxPoints[0], boxPoints[4], n[4], n[2] ) edge_poly( boxPoints[1], boxPoints[5], n[2], n[5] ) edge_poly( boxPoints[2], boxPoints[6], n[3], n[4] ) edge_poly( boxPoints[3], boxPoints[7], n[5], n[3] ) corner_poly( boxPoints[0], n[0], n[2], n[4] ) corner_poly( boxPoints[1], n[0], n[2], n[5] ) corner_poly( boxPoints[2], n[0], n[3], n[4] ) corner_poly( boxPoints[3], n[0], n[3], n[5] ) corner_poly( boxPoints[4], n[1], n[2], n[4] ) corner_poly( boxPoints[5], n[1], n[2], n[5] ) corner_poly( boxPoints[6], n[1], n[3], n[4] ) corner_poly( boxPoints[7], n[1], n[3], n[5] ) } //the rounded edges cylinder { boxPoints[0], boxPoints[1], rounding } cylinder { boxPoints[2], boxPoints[3], rounding } cylinder { boxPoints[4], boxPoints[5], rounding } cylinder { boxPoints[6], boxPoints[7], rounding } cylinder { boxPoints[0], boxPoints[2], rounding } cylinder { boxPoints[1], boxPoints[3], rounding } cylinder { boxPoints[4], boxPoints[6], rounding } cylinder { boxPoints[5], boxPoints[7], rounding } cylinder { boxPoints[0], boxPoints[4], rounding } cylinder { boxPoints[1], boxPoints[5], rounding } cylinder { boxPoints[2], boxPoints[6], rounding } cylinder { boxPoints[3], boxPoints[7], rounding } //corners #local ii=0; #while ( ii < 8 ) sphere { boxPoints[ii], rounding } #local ii = ii+1; #end } #end