public static Body Create(int segments, double radius, double height) { var creator = new GraphicsCreator(); double alpha = 2.0 * Math.PI / segments; double half = height / 2.0; double z0 = -half; double z1 = half; creator.AddFace(false, false); for (int i = 0; i < segments; i++) { double x0 = (Math.Sin(i * alpha) * radius); double y0 = (Math.Cos(i * alpha) * radius); double x1 = (Math.Sin((i + 1) * alpha) * radius); double y1 = (Math.Cos((i + 1) * alpha) * radius); var p1 = new Position3D(x0, y0, z0); var p2 = new Position3D(x0, y0, z1); var p3 = new Position3D(x1, y1, z0); var p4 = new Position3D(x1, y1, z1); creator.AddTriangle(p1, p2, p3); creator.AddTriangle(p3, p2, p4); } creator.AddFace(true, false); for (int i = 0; i < segments; i++) { double x0 = (Math.Sin(i * alpha) * radius); double y0 = (Math.Cos(i * alpha) * radius); double x1 = (Math.Sin(((i + 1) * alpha).Modulo2Pi()) * radius); double y1 = (Math.Cos(((i + 1) * alpha).Modulo2Pi()) * radius); double x2 = 0.0; double y2 = 0.0; var p1 = new Position3D(x0, y0, z1); var p2 = new Position3D(x1, y1, z1); var p3 = new Position3D(x2, y2, z1); creator.AddTriangle(p1, p3, p2); } creator.AddFace(true, false); for (int i = 0; i < segments; i++) { double x0 = (Math.Sin(i * alpha) * radius); double y0 = (Math.Cos(i * alpha) * radius); double x1 = (Math.Sin(((i + 1) * alpha).Modulo2Pi()) * radius); double y1 = (Math.Cos(((i + 1) * alpha).Modulo2Pi()) * radius); double x2 = 0.0; double y2 = 0.0; var p1 = new Position3D(x0, y0, z0); var p2 = new Position3D(x1, y1, z0); var p3 = new Position3D(x2, y2, z0); creator.AddTriangle(p1, p2, p3); } var body = creator.CreateBody(); return(body); }
private static void CreateSideFace( List <Position3D> topLoop1, List <Position3D> topLoop2, List <Position3D> bottomLoop1, List <Position3D> bottomLoop2, bool hasBorder1, bool hasBorder2, bool facetted1, bool facetted2, GraphicsCreator creator) { creator.AddFace(hasBorder1, facetted1); var n1 = topLoop1.Count; for (var i = 0; i < n1 - 1; i++) { var p1 = topLoop1[i]; var p2 = bottomLoop1[i]; var p3 = bottomLoop1[(i + 1) % n1]; var p4 = topLoop1[(i + 1) % n1]; creator.AddTriangle(p1, p2, p3); creator.AddTriangle(p4, p1, p3); } creator.AddFace(hasBorder2, facetted2); var n2 = topLoop2.Count; for (var i = 0; i < n2 - 1; i++) { var p1 = topLoop2[i]; var p2 = bottomLoop2[i]; var p3 = bottomLoop2[(i + 1) % n2]; var p4 = topLoop2[(i + 1) % n2]; creator.AddTriangle(p1, p2, p3); creator.AddTriangle(p4, p1, p3); } creator.AddFace(false, false); var pkt1 = topLoop1.Last(); var pkt2 = bottomLoop1.Last(); var pkt3 = bottomLoop2.First(); var pkt4 = topLoop2.First(); creator.AddTriangle(pkt1, pkt2, pkt3); creator.AddTriangle(pkt4, pkt1, pkt3); creator.AddFace(false, false); pkt1 = topLoop2.Last(); pkt2 = bottomLoop2.Last(); pkt3 = bottomLoop1.First(); pkt4 = topLoop1.First(); creator.AddTriangle(pkt1, pkt2, pkt3); creator.AddTriangle(pkt4, pkt1, pkt3); }
private static void CreateSideFace(List <Position3D> topLoop, List <Position3D> bottomLoop, GraphicsCreator creator) { creator.AddFace(false, false); var n = topLoop.Count; for (var i = 0; i < n; i++) { var p1 = topLoop[i]; var p2 = bottomLoop[i]; var p3 = bottomLoop[(i + 1) % n]; var p4 = topLoop[(i + 1) % n]; creator.AddTriangle(p1, p2, p3); creator.AddTriangle(p4, p1, p3); } }
public static Body Create(double size) { size = size > 0 ? size / 2.0 : 0.5; var p1 = new Position3D(-size, -size, -size); var p2 = new Position3D(size, -size, -size); var p3 = new Position3D(size, -size, size); var p4 = new Position3D(-size, -size, size); var p5 = new Position3D(-size, size, -size); var p6 = new Position3D(size, size, -size); var p7 = new Position3D(size, size, size); var p8 = new Position3D(-size, size, size); var creator = new GraphicsCreator(); // South creator.AddFace(true, false); creator.AddTriangle(p1, p2, p3); creator.AddTriangle(p3, p4, p1); // East creator.AddFace(true, false); creator.AddTriangle(p2, p6, p7); creator.AddTriangle(p7, p3, p2); // North creator.AddFace(true, false); creator.AddTriangle(p6, p5, p8); creator.AddTriangle(p8, p7, p6); // West creator.AddFace(true, false); creator.AddTriangle(p5, p1, p4); creator.AddTriangle(p4, p8, p5); // Top creator.AddFace(true, false); creator.AddTriangle(p4, p3, p7); creator.AddTriangle(p7, p8, p4); // Bottom creator.AddFace(true, false); creator.AddTriangle(p2, p1, p5); creator.AddTriangle(p5, p6, p2); var body = creator.CreateBody(); return(body); }
private static void CreateSection(GraphicsCreator creator, int circleSegments, double[] section, bool hasBorder, bool hasFacets) { creator.AddFace(hasBorder, hasFacets); double alpha = 2.0 * Math.PI / circleSegments; var n = section.Length - 2; for (int j = 0; j < n; j += 2) { double radius0 = section[j]; double radius1 = section[j + 2]; double z0 = section[j + 1]; double z1 = section[j + 3]; for (int i = 0; i < circleSegments; i++) { double x0 = (Math.Cos(i * alpha) * radius0); double y0 = (Math.Sin(i * alpha) * radius0); double x1 = (Math.Cos((i + 1) * alpha) * radius0); double y1 = (Math.Sin((i + 1) * alpha) * radius0); double x2 = (Math.Cos(i * alpha) * radius1); double y2 = (Math.Sin(i * alpha) * radius1); double x3 = (Math.Cos((i + 1) * alpha) * radius1); double y3 = (Math.Sin((i + 1) * alpha) * radius1); var p1 = new Position3D(x0, y0, z0); var p2 = new Position3D(x1, y1, z0); var p3 = new Position3D(x2, y2, z1); var p4 = new Position3D(x3, y3, z1); if (p1 != p2 && p2 != p4) { creator.AddTriangle(p1, p2, p4); } if (p1 != p3 && p3 != p4) { creator.AddTriangle(p4, p3, p1); } } } }
public static Body Create(int count, double size) { var creator = new GraphicsCreator(); var positions = CreatePositions(count, size); for (var y = 0; y < count; y++) { for (var x = 0; x < count; x++) { var point1 = positions[x][y]; var point2 = positions[x][y + 1]; var point3 = positions[x + 1][y + 1]; var point4 = positions[x + 1][y]; creator.AddFace(true, false); creator.AddTriangle(point1, point2, point4); creator.AddTriangle(point3, point4, point2); } } size = size * count; size = size > 0 ? size / 2.0 : 0.5; var hight = 2; var p1 = new Position3D(-size, -size, -hight); var p2 = new Position3D(size, -size, -hight); var p3 = new Position3D(size, -size, 0); var p4 = new Position3D(-size, -size, 0); var p5 = new Position3D(-size, size, -hight); var p6 = new Position3D(size, size, -hight); var p7 = new Position3D(size, size, 0); var p8 = new Position3D(-size, size, 0); // South creator.AddFace(true, false); creator.AddTriangle(p1, p2, p3); creator.AddTriangle(p3, p4, p1); // East creator.AddFace(true, false); creator.AddTriangle(p2, p6, p7); creator.AddTriangle(p7, p3, p2); // North creator.AddFace(true, false); creator.AddTriangle(p6, p5, p8); creator.AddTriangle(p8, p7, p6); // West creator.AddFace(true, false); creator.AddTriangle(p5, p1, p4); creator.AddTriangle(p4, p8, p5); // Bottom creator.AddFace(true, false); creator.AddTriangle(p2, p1, p5); creator.AddTriangle(p5, p6, p2); var body = creator.CreateBody(); return(body); }
private static (List <Position3D>, List <Position3D>) CreateTopBottomFace(int segments1, int segments2, double radius1, double radius2, double length, double depth, double z, GraphicsCreator creator, bool isTop) { var startAngle = Math.Acos((radius1 - radius2) / length); var endAngle = (-startAngle).Modulo2Pi(); var alpha1 = (endAngle - startAngle) / segments1; var sign = isTop ? 1.0 : -1.0; creator.AddFace(true, false); var pointsRadius1 = new List <Position3D>(); for (int i = 0; i < segments1; i++) { double x0 = (Math.Cos(i * alpha1 + startAngle) * radius1); double y0 = sign * (Math.Sin(i * alpha1 + startAngle) * radius1); double x1 = (Math.Cos(((i + 1) * alpha1 + startAngle).Modulo2Pi()) * radius1); double y1 = sign * (Math.Sin(((i + 1) * alpha1 + startAngle).Modulo2Pi()) * radius1); double x2 = 0.0; double y2 = 0.0; var p1 = new Position3D(x0, y0, z); var p2 = new Position3D(x1, y1, z); var p3 = new Position3D(x2, y2, z); creator.AddTriangle(p1, p2, p3); pointsRadius1.Add(p1); if (i == segments1 - 1) { pointsRadius1.Add(p2); } } var alpha2 = (2.0 * Math.PI - (endAngle - startAngle)) / segments2; startAngle = endAngle; var pointsRadius2 = new List <Position3D>(); for (int i = 0; i < segments2; i++) { double x0 = length + (Math.Cos(i * alpha2 + startAngle) * radius2); double y0 = sign * (Math.Sin(i * alpha2 + startAngle) * radius2); double x1 = length + (Math.Cos(((i + 1) * alpha2 + startAngle).Modulo2Pi()) * radius2); double y1 = sign * (Math.Sin(((i + 1) * alpha2 + startAngle).Modulo2Pi()) * radius2); double x2 = length; double y2 = 0.0; var p1 = new Position3D(x0, y0, z); var p2 = new Position3D(x1, y1, z); var p3 = new Position3D(x2, y2, z); creator.AddTriangle(p1, p2, p3); pointsRadius2.Add(p1); if (i == segments2 - 1) { pointsRadius2.Add(p2); } } var s1 = pointsRadius1.First(); var e1 = pointsRadius1.Last(); var m1 = new Position3D(0.0, 0.0, z); var s2 = pointsRadius2.First(); var e2 = pointsRadius2.Last(); var m2 = new Position3D(length, 0.0, z); creator.AddTriangle(s1, m1, e2); creator.AddTriangle(e2, m1, m2); creator.AddTriangle(m1, e1, m2); creator.AddTriangle(m2, e1, s2); if (!isTop) { pointsRadius1.Reverse(); pointsRadius2.Reverse(); } return(pointsRadius1, pointsRadius2); }