public static CSG Cylinder(CSGVector bottom, CSGVector top, int radius) { CylinderBottom = bottom; CylinderTop = top; CylinderRadius = radius; ray = CylinderTop.minus(CylinderBottom); int slices = 16; axisZ = ray.unit(); int isY = Math.Abs(axisZ.y) > 0.5 ? 1 : 0; axisX = new CSGVector(isY, 1 - isY, 0).cross(axisZ).unit(); axisY = axisX.cross(axisZ).unit(); CSGVertex start = new CSGVertex(CylinderBottom, axisZ.negated()); CSGVertex end = new CSGVertex(CylinderTop, axisZ.unit()); List <CSGPolygon> polygons = new List <CSGPolygon>(); for (int i = 0; i < slices; i++) { double t0 = (double)i / (double)slices; double t1 = (double)(i + 1) / (double)slices; polygons.Add(new CSGPolygon(start, point(0, t0, -1), point(0, t1, -1))); polygons.Add(new CSGPolygon(point(0, t1, 0), point(0, t0, 0), point(1, t0, 0), point(1, t1, 0))); polygons.Add(new CSGPolygon(end, point(1, t1, 1), point(1, t0, 1))); } return(CSG.fromPolygons(polygons)); }
public static CSGPlane fromPoints(CSGVector a, CSGVector b, CSGVector c) { CSGVector n = b.minus(a).cross(c.minus(a)).unit(); return(new CSGPlane(n, n.dot(a))); }
public CSGVector lerp(CSGVector a, float t) { return(this.plus(a.minus(this).times(t))); }