public xyz Diagonal() { xyz pmin = new xyz(xmin, ymin, zmin); xyz pmax = new xyz(xmax, ymax, zmax); return(pmax.subtract_in_place(pmin)); }
public static CompoundSolid Crosscut_Or_Rip(CompoundSolid sol, HalfEdge he, Inches distAlongEdge, double miter, double tilt) { Face f = he.face; // TODO fix these names string[] fnames = new string[] { "miter_top", "miter_right", "miter_left", "miter_bottom", "miter", // the primary face name which gets left "miter_below", }; xyz nrml = f.UnitNormal(); xyz origin = he.to + he.GetInwardNormal() * distAlongEdge; // vx is in the direction of the cut xyz vx = ut.RotateUnitVector(-he.UnitVector(), -miter, nrml); // now rotate nrml for tilt nrml = ut.RotateUnitVector(nrml, tilt, vx); // origin is going to be the corner of the cutter box. // right now it is sitting on the face. we need to // move it further away. calculate intersections with // the boundingbox of the compoundsolid as a whole. BoundingBox3d bb = sol.GetBoundingBox(); double d_vx = bb.IntersectRay_Planes_Max(origin, -vx); double d_nrml = bb.IntersectRay_Planes_Max(origin, nrml); // TODO this approach creates a bb which is too big. do we care? // now move origin far enough back behind the face origin.subtract_in_place((d_vx + 2) * vx); // and up above the face origin = origin + (d_nrml + 2) * nrml; xyz vy = xyz.cross(nrml, vx).normalize_in_place(); xyz vz = -nrml; d_vx = bb.IntersectRay_Planes_Max(origin, vx); double d_vy = bb.IntersectRay_Planes_Max(origin, vy); double d_vz = bb.IntersectRay_Planes_Max(origin, vz); // now calculate proper sizes for the cutter double dx = d_vx + 2; double dy = d_vy + 2; double dz = d_vz + 2; Solid cutter = CreateCutter_Box(string.Format("{0}_{1}", f.name, he.Opposite().face.name), origin, vx, nrml, new xyz(dx, dy, dz), fnames); //sol = sol.Clone(); //sol.AddSub(cutter); //return sol; return(bool3d.Subtract(sol, cutter)); }