public void SliceError_Case_004DF458() { var polyhedron = new Polyhedron(ValidateOption.Do, new[] { // Back face new Polygon(ValidateOption.Do, new Point(Inches, 181.75, 3.5, 0), new Point(Inches, 178.25, 3.5, 0), new Point(Inches, 178.25, 30.25, 0), new Point(Inches, 180.00, 30.25, 0), new Point(Inches, 181.75, 29.375, 0)), // Front face new Polygon(ValidateOption.Do, new Point(Inches, 178.25, 30.25, 1.5), new Point(Inches, 178.25, 3.5, 1.5), new Point(Inches, 181.75, 3.5, 1.5), new Point(Inches, 181.75, 29.375, 1.5), new Point(Inches, 180.00, 30.25, 1.5)), // Bottom face new Polygon(ValidateOption.Do, new Point(Inches, 181.75, 3.5, 0), new Point(Inches, 181.75, 3.5, 1.5), new Point(Inches, 178.25, 3.5, 1.5), new Point(Inches, 178.25, 3.5, 0)), // Left face new Polygon(ValidateOption.Do, new Point(Inches, 178.25, 3.5, 0), new Point(Inches, 178.25, 3.5, 1.5), new Point(Inches, 178.25, 30.25, 1.5), new Point(Inches, 178.25, 30.25, 0)), // Right face new Polygon(ValidateOption.Do, new Point(Inches, 181.75, 3.5, 1.5), new Point(Inches, 181.75, 3.5, 0), new Point(Inches, 181.75, 29.375, 0), new Point(Inches, 181.75, 29.375, 1.5)), // Top face new Polygon(ValidateOption.Do, new Point(Inches, 178.25, 30.25, 0), new Point(Inches, 178.25, 30.25, 1.5), new Point(Inches, 180.00, 30.25, 1.5), new Point(Inches, 180.00, 30.25, 0)), // Cut face new Polygon(ValidateOption.Do, new Point(Inches, 180.00, 30.25, 0), new Point(Inches, 180.00, 30.25, 1.5), new Point(Inches, 181.75, 29.375, 1.5), new Point(Inches, 181.75, 29.375, 0)), }); var slicingPlane = new Plane(new Point(Inches, 127.31379563066, 3.5, 1.5), new Direction(0.452633527072262, -0.891696635728836, 0)); var sliceResults = polyhedron.Slice(slicingPlane); }
public static Polyhedron CreateIcosahedron() { Polyhedron Icosahedron = new Polyhedron(); Point3d[] verts = new Point3d[12]; // верх и низ verts[0] = new Point3d(0, 0, 1); verts[1] = new Point3d(0, 0, -1); double h = Math.Sqrt(5) / 5; double R = h / Math.Sin(Math.PI / 5); // верхний круг double angle = 0; for (int i = 2; i < 7; ++i) { verts[i] = new Point3d(R * Math.Sin(angle), R * Math.Cos(angle), h); angle += 72 * Math.PI / 180; } // нижний круг angle = 36 * Math.PI / 180; for (int i = 7; i < 12; ++i) { verts[i] = new Point3d(R * Math.Sin(angle), R * Math.Cos(angle), -h); angle += 72 * Math.PI / 180; } Icosahedron.faces = new Face[20]; for (int i = 0; i < 4; ++i) { Icosahedron.faces[2 * i] = Face.CreateTriangle(verts[0], verts[2 + i], verts[3 + i]); Icosahedron.faces[2 * i + 1] = Face.CreateTriangle(verts[1], verts[7 + i], verts[8 + i]); } Icosahedron.faces[8] = Face.CreateTriangle(verts[0], verts[2], verts[6]); Icosahedron.faces[9] = Face.CreateTriangle(verts[1], verts[7], verts[11]); for (int i = 0; i < 4; ++i) { Icosahedron.faces[10 + 2 * i] = Face.CreateTriangle(verts[2 + i], verts[3 + i], verts[7 + i]); Icosahedron.faces[11 + 2 * i] = Face.CreateTriangle(verts[7 + i], verts[8 + i], verts[3 + i]); } Icosahedron.faces[18] = Face.CreateTriangle(verts[6], verts[2], verts[11]); Icosahedron.faces[19] = Face.CreateTriangle(verts[11], verts[7], verts[2]); Icosahedron.center = new Point3d(0, 0, 0); return(Icosahedron); }
static public List <Edge> ToPerspective(Polyhedron ph, int c) { List <Edge> res = new List <Edge>(); var edges_3d = ph.PreparePrint(); var matr = FormPerspectiveMatr(c); foreach (var edge in edges_3d) { var new_start = MatrixMultiplication(PointToVector(edge.start), matr); var new_end = MatrixMultiplication(PointToVector(edge.end), matr); res.Add(new Edge(VectorToPoint(new_start), VectorToPoint(new_end))); } return(res); }
static public List <Edge> ToOrtographics(Polyhedron ph, OrtMode plain) { List <Edge> edges = new List <Edge>(); var edges_3d = ph.PreparePrint(); var ort_matr = FormOrtoghraphicsMatr(plain); foreach (var edge in edges_3d) { var new_start = MatrixMultiplication(PointToVector(edge.start), ort_matr); var new_end = MatrixMultiplication(PointToVector(edge.end), ort_matr); edges.Add(new Edge(VectorToPoint(new_start), VectorToPoint(new_end))); } return(edges); }
private Color TraceRay(Point3d camera, Point3d D, float t_min, float t_max, float depth, int step) { float closest_t = inf; Polyhedron closest = null; Point3d normal = null; Point3d point = null; ClosestIntersection(camera, D, t_min, t_max, ref closest, ref closest_t, ref normal); //если луч уходит вникуда if (closest == null) { return(background_color); } //привели к единичной normal = multiply(1.0f / length(normal), normal); point = add(camera, multiply(closest_t, D)); //высчитываем освещенность var light_k = ComputeLighting(point, normal, multiply(-1, D), closest.specular); Color local = increase(light_k, closest.color); //добавляем отражения if (step > 7 || depth <= eps) { return(local); } var r = ReflectRay(multiply(-1, D), normal); var refl_color = TraceRay(point, r, eps, inf, depth * closest.reflective, step + 1); //сумма полученного цвета и пришедшего из отраженного луча Color reflected = sum(increase(1 - closest.reflective, local), increase(closest.reflective, refl_color)); if (closest.transparent <= 0) { return(increase(depth, reflected)); } //добавить прозрачность //допустим, что луч не преломляется //index of refraction - 1.5 var refracted = refract(D, normal, 1.5f); var tr_color = TraceRay(point, refracted, eps, inf, depth * closest.transparent, step + 1); //допустим, что луч не преломляется /*var tr_color = TraceRay(point, D, eps, inf, depth * closest.transparent, step+1);*/ Color transp = sum(increase(1 - closest.transparent, reflected), increase(closest.transparent, tr_color)); return(increase(depth, transp)); }
private void light_TextChanged(object sender, EventArgs e) { Polyhedron light = new Polyhedron(); light.make_hexahedron(5); check_all_textboxes(); light.translate(int.Parse(light_x.Text), int.Parse(light_y.Text), int.Parse(light_z.Text)); g.Clear(Color.White); figure.show(g, pr); camera.show(g, pr); light.show(g, pr, new Pen(Color.YellowGreen)); if (radioButton3.Checked) { show_gouraud(); } }
public Poly(Polyhedron p) { ph = p.Clone() as Polyhedron; sph = new Sphere(ph); squares.Clear(); foreach (var face in ph.Faces) { double s = 0; int cnt = face.Edges.Count(); for (int i = 1; i < cnt - 1; ++i) { s += triangle_square(face.Edges[0].First, face.Edges[i].First, face.Edges[i + 1].First); } squares.Add(face, s); } }
private void SetPolyhedron(string name) { _polyhedron = Data.Polyhedra.First(p => p.Name.Contains(name)); Polyhedron.mesh = PolyhedronMeshes.First(inf => inf.name == _polyhedron.Name); Debug.LogFormat(@"[Polyhedral Maze #{0}] Your polyhedron is a {1}.", _moduleId, _polyhedron.ReadableName); // Find a suitable start face _startFace = _startingPositions.PickRandom(); Debug.LogFormat(@"[Polyhedral Maze #{0}] You are starting on face #{1}.", _moduleId, _startFace); // Run a breadth-first search to determine a destination face that is the desired number of steps away var qFaces = new Queue <int>(); qFaces.Enqueue(_startFace); var qDistances = new Queue <int>(); qDistances.Enqueue(0); var already = new HashSet <int>(); var suitableDestinationFaces = new List <int>(); while (qFaces.Count > 0) { var face = qFaces.Dequeue(); var distance = qDistances.Dequeue(); if (!already.Add(face)) { continue; } if (distance >= _minSteps && distance <= _maxSteps) { suitableDestinationFaces.Add(face); } var permissible = _permissibleTransitions[face]; foreach (var adj in _polyhedron.Faces[face].AdjacentFaces) { if (permissible.Contains(adj)) { qFaces.Enqueue(adj); qDistances.Enqueue(distance + 1); } } } _destFace = suitableDestinationFaces.PickRandom(); setDisplay(DestTens, DestOnes, _destFace); SetCurFace(_startFace); Debug.LogFormat(@"[Polyhedral Maze #{0}] You need to go to face #{1}.", _moduleId, _destFace); }
// Return the distance of the furthest point from the pivot in the center of the root face private static float spread(Polyhedron polyhedron, Vector3 pivot) { float maxD2 = 0f; foreach (Face face in polyhedron.Faces) { foreach (Vector3 v in face.Points) { float d2 = (v - pivot).LengthSq(); if (d2 > maxD2) { maxD2 = d2; } } } return((float)Math.Sqrt(maxD2)); }
public List <Edge> Project(Mode m, Polyhedron p) { switch (m) { case Mode.Orthographic: return(ToOrtographics(p)); case Mode.Isometric: return(ToIsometric(p)); case Mode.Perspective: return(ToPerspective(p)); default: return(new List <Edge>()); } }
// rotation_figure private void button3_Click_1(object sender, EventArgs e) { if (openFileDialog1.ShowDialog() == DialogResult.Cancel) { return; } string filename = openFileDialog1.FileName; string fileText = System.IO.File.ReadAllText(filename); figure = new Polyhedron(fileText, Polyhedron.MODE_ROT); g.Clear(Color.White); figure.show(g, pr); create_camera(); label10.Text = figure.Center.X.ToString() + ", " + figure.Center.Y.ToString() + ", " + figure.Center.Z.ToString(); }
public void ComputeVertices() { if (Faces.Count < 4) { return; } Polyhedron poly = new Polyhedron(Faces.Select(x => new Plane(x.Plane.Normal.ToPrecisionVector3(), x.Plane.D))); foreach (Face face in Faces) { Polygon pg = poly.Polygons.FirstOrDefault(x => x.Plane.Normal.EquivalentTo(face.Plane.Normal.ToPrecisionVector3(), 0.0075f)); // Magic number that seems to match VHE if (pg != null) { face.Vertices.AddRange(pg.Vertices.Select(x => x.ToStandardVector3())); } } }
/// <summary> /// Do the actual projection of the supplied polygon into the canvas /// Before the actual projection the polyhedron is rotation by the yaw angle around a vertical Y axis through the pivot point /// at the center of the root Face. /// The viewpoint is raised vertically and turned to look down towards the polyhedron (an X axis rotation) /// The the persective transformation is applied before the Polygons are generated. The z dimension in Vector3 /// is used to generate the z-index in the xaml polygons /// </summary> /// <param name="polyhedron"></param> /// <param name="yaw"></param> /// <param name="pivot"></param> /// <param name="mag"></param> /// <param name="canvas"></param> public static void Project(Polyhedron polyhedron, float yaw, Vector3 pivot, float mag, Canvas canvas) { float angle = (float)Math.PI / 4; float w = spread(polyhedron, pivot) * mag; Vector3 viewPoint = new Vector3(0, w * 0.6f, w); pivot.Y = -w / 2; if (polyhedron.Faces.Count <= 8) { pivot.Y += w / 4; } Matrix projection = Matrix.Translation(-pivot) * Matrix.RotationY(yaw) * Matrix.RotationX(angle) * Matrix.Translation(viewPoint) * Geometry.Perspective(5); Canvas childCanvas = new Canvas(); childCanvas.Width = canvas.Width; childCanvas.Height = canvas.Height; Vector3 projectedPivot = Vector3.TransformCoordinate(pivot, projection); foreach (Face face in polyhedron.Faces) { Vector3[] p = Vector3.TransformCoordinate(face.Points, projection); Vector3 c = Geometry.Center(p); int zIndex = -(int)(c.Z * int.MaxValue / 200); System.Windows.Shapes.Polygon pg = new System.Windows.Shapes.Polygon(); pg.SetValue(Canvas.ZIndexProperty, zIndex); Point[] points = Geometry.Vector3ToPoint(p, projectedPivot.X - w / 2, projectedPivot.Y - w / 2, w, (float)canvas.Width, (float)canvas.Height); //pg.Points. = points; ////// CHANGE !!!! foreach (Point pt in points) { pg.Points.Add(pt); } pg.StrokeThickness = 1; pg.Stroke = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Colors.Black); System.Windows.Media.Color col = PolyhedronPalette.Lookup(face.NumSides); pg.Fill = new System.Windows.Media.SolidColorBrush(col); pg.Opacity = 0.8; childCanvas.Children.Add(pg); } canvas.Children.Clear(); canvas.Children.Add(childCanvas); }
static public Polyhedron CreateTetrahedron(Point3D start, float a) { Polyhedron res = new Polyhedron(start); Point3D start_x = new Point3D(start.X + a, start.Y, start.Z); Point3D start_y = new Point3D(start.X, start.Y + a, start.Z); Point3D start_z = new Point3D(start.X, start.Y, start.Z + a); Point3D start_xy = new Point3D(start_x.X, start_y.Y, start.Z); Point3D start_xz = new Point3D(start_x.X, start.Y, start_z.Z); Point3D start_yz = new Point3D(start.X, start_y.Y, start_z.Z); res.AddPoint(start, start_xy); res.AddPoint(start, start_xz); res.AddPoint(start, start_yz); res.AddPoint(start_xz, start_yz); res.AddPoint(start_xz, start_xy); res.AddPoint(start_yz, start_xy); return(res); }
private void Ok(object sender, EventArgs e) { var tab = tabControl1.SelectedTab; if (tabPagePolyhedron == tab) { if (radioButtonTetrahedron.Checked) { selectedModel = Polyhedron.MakeTetrahedron(0.5); } else if (radioButtonIcosahedron.Checked) { selectedModel = Polyhedron.MakeIcosahedron(0.5); } else if (radioButtonHexahedron.Checked) { selectedModel = Polyhedron.MakeHexahedron(0.5); } else if (radioButtonOctahedron.Checked) { selectedModel = Polyhedron.MakeOctahedron(1); } } else if (tabPageRotationFigure == tab) { var initial = new List <Point3D>(); foreach (var p in listBoxPoints.Items) { initial.Add((Point3D)p); } int axis; if (radioButtonX.Checked) { axis = 0; } else if (radioButtonY.Checked) { axis = 1; } else /* if (radioButtonZ.Checked) */ axis {
public Polyhedron Clone() { Polyhedron cl = new Polyhedron(); //List<Point3D> npoints = new List<Point3D>(); //Dictionary<int, List<int>> nconnections = new Dictionary<int, List<int>>(); cl.points = new List <Point3D>(); cl.connections = new Dictionary <int, List <int> >(); for (int i = 0; i < points.Count; ++i) { cl.points.Add(new Point3D(points[i].X, points[i].Y, points[i].Z)); } for (int i = 0; i < connections.Count; i++) { cl.connections[i] = new List <int>(); for (int j = 0; j < connections[i].Count; j++) { cl.connections[i].Add(connections[i][j]); } } return(cl); }
public Sphere(Polyhedron ph) { var p = ph.Faces[0].Edges[0].First; var dist = new Vector(ph.Center, p).Norm(); foreach (var f in ph.Faces) { foreach (var e in f.Edges) { var pp = e.First; var ddist = new Vector(ph.Center, pp).Norm(); if (ddist > dist) { dist = ddist; p = pp; } } } this.center = ph.Center; this.radius = dist; }
private Polyhedron SubdividePolyhedron(Polyhedron initialPolyhedron, int divisions, bool registerFaces = true, bool registerRegions = true) { var addPoint = CreatePointAdder(initialPolyhedron.Corners); var newFaces = new List <Face>(); foreach (var(face, index) in initialPolyhedron.Faces.WithIndex()) { var dividedFaces = registerRegions ? SubdivideFace(face, divisions, addPoint, registerFaces, index) : SubdivideFace(face, divisions, addPoint, registerFaces); newFaces.AddRange(dividedFaces); } var newPoints = newFaces.SelectMany(f => f.Points).Distinct().ToList(); return(new Polyhedron { Corners = newPoints, Faces = newFaces }); }
private HexSphere MapPolyhedronToHexasphere(Polyhedron polyhedron, float radius, float hexSize) { polyhedron.Corners = polyhedron.Corners.Select(p => PointHelpers.ProjectToRadius(p, radius)).ToList(); var numRegions = polyhedron.Corners.Select(p => p.Region ?? 0).Max() + 1; var regions = Enumerable.Range(0, numRegions) .Select(_ => new TileRegion { Tiles = new List <Tile>() }) .ToList(); foreach (var p in polyhedron.Corners) { var center = p; var faces = PointHelpers.GetOrderedFaces(center); var boundaryPoints = faces.Select(f => Segment(center, f.Centroid, hexSize)).ToList(); var tile = new Tile { Center = center, Boundary = boundaryPoints.Select(p2 => p2 as Point).ToList() }; if (!IsPoitingAwayFromOrigin(tile)) { tile.Boundary.Reverse(); } var regionId = p.Region ?? 0; regions[regionId].Tiles.Add(tile); } return(new HexSphere { Regions = regions }); }
private void create_scene() { Viewport_w = 1; Viewport_h = 1; projection_plane_d = 1; rec_depth = 3; create_camera(new Point3d(0, 3, -15)); if (scene != null) { scene.Clear(); } var figure = new Polyhedron(); figure.make_sphere(new Point3d(0, 2, 3), 1); figure.color = Color.Red; figure.specular = 500; figure.reflective = 0.2f; figure.comment = "шар"; scene.Add(figure); sceneBox.Items.Add("SPHERE0"); figure = new Polyhedron(); figure.make_sphere(new Point3d(2, 0, 4), 1); figure.color = Color.Yellow; figure.specular = 500; figure.reflective = 0.3f; figure.transparent = 0.9f; figure.comment = "еще шар"; scene.Add(figure); sceneBox.Items.Add("SPHERE1"); figure = new Polyhedron(); figure.make_sphere(new Point3d(-2, 0, 4), 1); figure.color = Color.Green; figure.specular = 500; figure.reflective = 0.9f; figure.comment = "и снова шар"; scene.Add(figure); sceneBox.Items.Add("SPHERE2"); figure = new Polyhedron(); figure.make_sphere(new Point3d(-1, 8, 3), 0.5f); figure.color = Color.LightPink; figure.specular = 500; figure.reflective = 0f; figure.transparent = 0.7f; scene.Add(figure); sceneBox.Items.Add("SPHERE3"); figure = new Polyhedron(); figure.make_sphere(new Point3d(1, 8, 1), 0.5f); figure.color = Color.LightSkyBlue; figure.specular = 500; figure.reflective = 0f; figure.transparent = 0.7f; scene.Add(figure); sceneBox.Items.Add("SPHERE4"); figure = new Polyhedron(); figure.make_sphere(new Point3d(4, 8, 5), 0.5f); figure.color = Color.Lime; figure.specular = 500; figure.reflective = 0f; figure.transparent = 0.7f; scene.Add(figure); sceneBox.Items.Add("SPHERE5"); figure = new Polyhedron(); figure.make_hexahedron(1f); figure.translate(0, 0, 3); figure.color = Color.YellowGreen; figure.specular = 500; figure.reflective = 0.1f; figure.transparent = 0.5f; figure.comment = ""; figure.find_normals(); scene.Add(figure); sceneBox.Items.Add("CUBE0"); figure = new Polyhedron(); figure.make_hexahedron(2f); figure.translate(-8, 1, 0); figure.color = Color.Pink; figure.specular = 500; figure.reflective = 0.4f; figure.transparent = 0f; figure.comment = ""; figure.find_normals(); scene.Add(figure); sceneBox.Items.Add("CUBE1"); figure = new Polyhedron(); figure.make_hexahedron(1f); figure.rotate(45, Axis.AXIS_Y); figure.translate(-8, 4f, 0); figure.color = Color.PowderBlue; figure.specular = 500; figure.reflective = 0.4f; figure.transparent = 0f; figure.comment = ""; figure.find_normals(); scene.Add(figure); sceneBox.Items.Add("CUBE2"); figure = new Polyhedron(); figure.make_hexahedron(0.5f); figure.translate(-8, 5.5f, 0); figure.color = Color.YellowGreen; figure.specular = 500; figure.reflective = 0.1f; figure.transparent = 0f; figure.comment = ""; figure.find_normals(); scene.Add(figure); sceneBox.Items.Add("CUBE3"); Face f = new Face(new List <Point3d>() { new Point3d(-10, -1, 10), new Point3d(-10, 10, 10), new Point3d(10, 10, 10), new Point3d(10, -1, 10) }); figure = new Polyhedron(new List <Face>() { f }); figure.Faces[0].Normal = new List <float>() { 0, 0, 1 }; figure.color = Color.White; figure.specular = 0; figure.reflective = 0f; figure.comment = "back"; scene.Add(figure); sceneBox.Items.Add("WALL0"); f = new Face(new List <Point3d>() { new Point3d(-10, -1, -10), new Point3d(-10, -1, 10), new Point3d(10, -1, 10), new Point3d(10, -1, -10) }); figure = new Polyhedron(new List <Face>() { f }); figure.Faces[0].Normal = new List <float>() { 0, -1, 0 }; figure.color = Color.White; figure.specular = 0; figure.reflective = 0f; figure.comment = "down"; figure.color = Color.LightGray; scene.Add(figure); sceneBox.Items.Add("WALL1"); f = new Face(new List <Point3d>() { new Point3d(-10, 10, -10), new Point3d(-10, 10, 10), new Point3d(10, 10, 10), new Point3d(10, 10, -10) }); figure = new Polyhedron(new List <Face>() { f }); figure.Faces[0].Normal = new List <float>() { 0, 1, 0 }; figure.color = Color.White; figure.specular = 0; figure.reflective = 0f; figure.comment = "top"; figure.color = Color.Red; scene.Add(figure); sceneBox.Items.Add("WALL2"); f = new Face(new List <Point3d>() { new Point3d(-10, -1, -10), new Point3d(-10, 10, -10), new Point3d(-10, 10, 10), new Point3d(-10, -1, 10) }); figure = new Polyhedron(new List <Face>() { f }); figure.Faces[0].Normal = new List <float>() { -1, 0, 0 }; figure.color = Color.White; figure.specular = 0; figure.reflective = 0f; figure.comment = "left"; figure.color = Color.Green; scene.Add(figure); sceneBox.Items.Add("WALL3"); f = new Face(new List <Point3d>() { new Point3d(10, -1, -10), new Point3d(10, 10, -10), new Point3d(10, 10, 10), new Point3d(10, -1, 10) }); figure = new Polyhedron(new List <Face>() { f }); figure.Faces[0].Normal = new List <float>() { 1, 0, 0 }; figure.color = Color.White; figure.specular = 0; figure.reflective = 0f; figure.comment = "right"; figure.color = Color.Ivory; scene.Add(figure); sceneBox.Items.Add("WALL4"); f = new Face(new List <Point3d>() { new Point3d(-10, -1, -10), new Point3d(-10, 10, -10), new Point3d(10, 10, -10), new Point3d(10, -1, -10) }); figure = new Polyhedron(new List <Face>() { f }); figure.Faces[0].Normal = new List <float>() { 0, 0, -1 }; figure.color = Color.White; figure.specular = 0; figure.reflective = 0f; figure.comment = "front"; scene.Add(figure); sceneBox.Items.Add("WALL5"); sceneBox.SelectedIndex = 0; }
internal static string ToCodeString(this Polyhedron polyhedron) { return($"new Polyhedron(ValidateOption.Dont, {ToCodeString(polyhedron.Faces, Dimensions._3D)})"); }
void Start() { Polyhedron.GetPyramid().Create(floorSize); }
public void Slice_Horizontal_Cut_Right() { var polyhedron = new Polyhedron(ValidateOption.Do, new[] { new Polygon(ValidateOption.Do, new Point(Inches, 120, 60.25, 0), new Point(Inches, 120, 64.16311896, 0), new Point(Inches, 260, -5.83688104, 0), new Point(Inches, 260, -9.75, 0)), new Polygon(ValidateOption.Do, new Point(Inches, 260, -9.75, 0), new Point(Inches, 260, -9.75, 1.5), new Point(Inches, 120, 60.25, 1.5), new Point(Inches, 120, 60.25, 0)), new Polygon(ValidateOption.Do, new Point(Inches, 260, -5.83688104, 0), new Point(Inches, 260, -5.83688104, 1.5), new Point(Inches, 260, -9.75, 1.5), new Point(Inches, 260, -9.75, 0)), new Polygon(ValidateOption.Do, new Point(Inches, 120, 64.16311896, 0), new Point(Inches, 120, 64.16311896, 1.5), new Point(Inches, 260, -5.83688104, 1.5), new Point(Inches, 260, -5.83688103999999, 0)), new Polygon(ValidateOption.Do, new Point(Inches, 120, 60.25, 0), new Point(Inches, 120, 60.25, 1.5), new Point(Inches, 120, 64.16311896, 1.5), new Point(Inches, 120, 64.16311896, 0)), new Polygon(ValidateOption.Do, new Point(Inches, 120, 60.25, 1.5), new Point(Inches, 260, -9.75, 1.5), new Point(Inches, 260, -5.83688103999999, 1.5), new Point(Inches, 120, 64.16311896, 1.5)) }); var slicingPlane = new Plane(new Point(Inches, 12, -1.83688103937537, 0), new Direction(0, -1, 0)); var referencePoint = new Point(Inches, 120, 62.2065594799946, 0); var sliceResults = polyhedron.Slice(slicingPlane, referencePoint); #region Expected Solid var expected = new Polyhedron(ValidateOption.Do, new[] { new Polygon(ValidateOption.Do, new Point(Inches, 120, 60.25, 0), new Point(Inches, 120, 64.16311896, 0), new Point(Inches, 252, -1.83688104, 0), new Point(Inches, 244.173762078751, -1.83688104, 0)), new Polygon(ValidateOption.Do, new Point(Inches, 244.173762078751, -1.83688104, 0), new Point(Inches, 244.173762078751, -1.83688104, 1.5), new Point(Inches, 120, 60.25, 1.5), new Point(Inches, 120, 60.25, 0)), new Polygon(ValidateOption.Do, new Point(Inches, 252, -1.83688104, 0), new Point(Inches, 252, -1.83688104, 1.5), new Point(Inches, 244.173762078751, -1.83688104, 1.5), new Point(Inches, 244.173762078751, -1.83688104, 0)), new Polygon(ValidateOption.Do, new Point(Inches, 120, 64.16311896, 0), new Point(Inches, 120, 64.16311896, 1.5), new Point(Inches, 252, -1.83688104, 1.5), new Point(Inches, 252, -1.83688103999999, 0)), new Polygon(ValidateOption.Do, new Point(Inches, 120, 60.25, 0), new Point(Inches, 120, 60.25, 1.5), new Point(Inches, 120, 64.16311896, 1.5), new Point(Inches, 120, 64.16311896, 0)), new Polygon(ValidateOption.Do, new Point(Inches, 120, 60.25, 1.5), new Point(Inches, 244.173762078751, -1.83688104, 1.5), new Point(Inches, 252, -1.83688103999999, 1.5), new Point(Inches, 120, 64.16311896, 1.5)) }); #endregion sliceResults.First().Should().Be(expected); }
//// graphic //private void button4_Click_1(object sender, EventArgs e) //{ // Form2 form2 = new Form2(); // form2.ShowDialog(); // var f = form2.f; // float x0 = form2.X0; // float x1 = form2.X1; // float y0 = form2.Y0; // float y1 = form2.Y1; // int cnt_of_breaks = form2.Cnt_of_breaks; // form2.Dispose(); // float dx = (Math.Abs(x0) + Math.Abs(x1)) / cnt_of_breaks; // float dy = (Math.Abs(y0) + Math.Abs(y1)) / cnt_of_breaks; // List<Face> faces = new List<Face>(); // List<Point3d> pts0 = new List<Point3d>(); // List<Point3d> pts1 = new List<Point3d>(); // for (float x = x0; x < x1; x += dx) // { // for (float y = y0; y < y1; y += dy) // { // float z = f(x, y); // pts1.Add(new Point3d(x, y, z)); // } // // make faces // if (pts0.Count != 0) // for (int i = 1; i < pts0.Count; ++i) // { // faces.Add(new Face(new List<Point3d>() { // new Point3d(pts0[i - 1]), new Point3d(pts1[i - 1]), // new Point3d(pts1[i]), new Point3d(pts0[i]) // })); // } // pts0.Clear(); // pts0 = pts1; // pts1 = new List<Point3d>(); // } // g.Clear(Color.White); // figure = new Polyhedron(faces); // figure.show(g, pr, new_fig); //} // graphic private void button4_Click_1(object sender, EventArgs e) { Form2 form2 = new Form2(); form2.ShowDialog(); var f = form2.f; float x0 = form2.X0; float x1 = form2.X1; float y0 = form2.Y0; float y1 = form2.Y1; int cnt_of_breaks = form2.Cnt_of_breaks; form2.Dispose(); ReverseFloatComparer fcmp = new ReverseFloatComparer(); float dx = (Math.Abs(x0) + Math.Abs(x1)) / cnt_of_breaks; float dy = (Math.Abs(y0) + Math.Abs(y1)) / cnt_of_breaks; List <Face> faces = new List <Face>(); List <Point3d> pts0 = new List <Point3d>(); List <Point3d> pts1 = new List <Point3d>(); //SortedDictionary<float, PointF> graph_function = new SortedDictionary<float, PointF>(fcmp); // z, (x, y) for (float x = x0; x < x1; x += dx) { for (float y = y0; y < y1; y += dy) { float z = f(x, y); //graph_function.Add(z, new PointF(x, y)); pts1.Add(new Point3d(x, y, z)); } // make faces if (pts0.Count != 0) { for (int i = 1; i < pts0.Count; ++i) { faces.Add(new Face(new List <Point3d>() { new Point3d(pts0[i - 1]), new Point3d(pts1[i - 1]), new Point3d(pts1[i]), new Point3d(pts0[i]) })); } } pts0.Clear(); pts0 = pts1; pts1 = new List <Point3d>(); } g.Clear(Color.White); figure = new Polyhedron(faces); figure.is_graph = true; figure.graph_function = f; //figure.graph_function = graph_function; figure.show(g, pr, new_fig); //figure.show_camera(g_camera, camera.view, new_fig); create_camera(); }
private void dodecahedron_Click(object sender, EventArgs e) { cur_polyhedron = CreateDodecahedron(start_point, 100); Draw(); }
private void Cub_Button_Click(object sender, EventArgs e) { cur_polyhedron = CreateCube(start_point, 100); Draw(); }
private void TestHE() { string str = @"D:\cgal_boolean.stl"; //str = "d:/tmp/plane3.stl"; Mesh mesh = ImportModel(str); Polyhedron poly = new Polyhedron(mesh); var vv = poly.VV(poly.vList[0]); var vf = poly.VF(poly.vList[0]); var holes = poly.FindHoles(); var veo = poly.VEO(poly.vList[0]); var vei = poly.VEI(poly.vList[0]); //double dist= poly.GDBase(poly.vList[1], poly.vList[2]); var src = poly.vList[m_Random.Next(1, poly.vList.Count - 1)]; var dst = poly.vList[m_Random.Next(1, poly.vList.Count - 1)]; { List <Vertex> path; double dist2 = poly.GD_OLD(src, dst, out path); eyeshot.Entities.Add(new Joint(src, 0.1, 1), 0, Color.White); eyeshot.Entities.Add(new Joint(dst, 0.1, 1), 0, Color.Black); for (int i = 0; i + 1 < path.Count; i++) { Line l = new Line(path[i], path[i + 1]); l.LineWeight = 6; l.LineWeightMethod = colorMethodType.byEntity; eyeshot.Entities.Add(l, 0, Color.Red); } Console.WriteLine("geo dist = " + dist2.ToString()); } { List <Vertex> path; double dist2 = poly.GD(src, dst, out path); //eyeshot.Entities.Add(new Joint(src, 0.1, 1), 0, Color.White); //eyeshot.Entities.Add(new Joint(dst, 0.1, 1), 0, Color.Black); for (int i = 0; i + 1 < path.Count; i++) { Line l = new Line(path[i], path[i + 1]); l.LineWeight = 6; l.LineWeightMethod = colorMethodType.byEntity; eyeshot.Entities.Add(l, 0, Color.Yellow); } Console.WriteLine("geo dist = " + dist2.ToString()); } Console.WriteLine(holes.Count.ToString() + " holes was found!"); foreach (var hole in holes) { Color c = RandomColor(); foreach (var he in hole) { Edge e = new Edge(he); Line l = new Line(poly.vList[e.V1], poly.vList[e.V2]); l.LineWeight = 3; l.LineWeightMethod = colorMethodType.byEntity; eyeshot.Entities.Add(l, 0, c); } } eyeshot.Entities.Add(poly, 0, Color.Green); eyeshot.Invalidate(); eyeshot.ZoomFit(); // Debugger.Break(); }
private void ClosestIntersection(Point3d camera, Point3d D, float t_min, float t_max, ref Polyhedron closest, ref float closest_t, ref Point3d norm) { closest_t = inf; closest = null; norm = null; foreach (var pol in scene) { if (pol.is_sphere) { PointF t = IntersectRaySphere(camera, D, pol); //t.x - первый корень, t.y - второй if (t.X < closest_t && t_min < t.X && t.X < t_max) { closest_t = t.X; closest = pol; } if (t.Y < closest_t && t_min < t.Y && t.Y < t_max) { closest_t = t.Y; closest = pol; } } else { Point3d norm_2 = null; Point3d point_2 = null; float t = intersectRay(camera, D, pol, ref norm_2); if (t < closest_t && t_min < t && t < t_max) { closest_t = t; closest = pol; norm = norm_2; } } } if (closest != null && closest.is_sphere) { var point = add(camera, multiply(closest_t, D)); norm = sub(point, closest.Center); } }
private Point3d ComputeLighting(Point3d point, Point3d normal, Point3d view, float specular) { Point3d intensity = new Point3d(0, 0, 0); float length_n = length(normal); // Should be 1.0, but just in case... float length_v = length(view); float t_max = 0; for (int i = 0; i < lights.Count; ++i) { Light light = lights[i]; if (!light.enabled) { continue; } if (light.type == LightType.lAmbient) { intensity.X += light.r_intensity; intensity.Y += light.g_intensity; intensity.Z += light.b_intensity; } else { Point3d vec_l; if (light.type == LightType.lPoint) { vec_l = sub(light.position, point); t_max = 1f; } else { // Light.DIRECTIONAL vec_l = light.position; t_max = inf; } //is shadow Polyhedron blocker = null; float closest_t = 0f; Point3d norm = null; Point3d point_t = null; ClosestIntersection(point, vec_l, eps, t_max, ref blocker, ref closest_t, ref norm); float tr = 1; if (blocker != null) { //tr = blocker.transparent; continue; } //diffuse var n_dot_l = dot(normal, vec_l); if (n_dot_l > 0) { //intensity += light_int * n_dot_l / (length_n * length(vec_l)); intensity.X += tr * light.r_intensity * n_dot_l / (length_n * length(vec_l)); intensity.Y += tr * light.g_intensity * n_dot_l / (length_n * length(vec_l)); intensity.Z += tr * light.b_intensity * n_dot_l / (length_n * length(vec_l)); } //specular if (specular > 0) { var vec_r = ReflectRay(vec_l, normal); var r_dot_v = dot(vec_r, view); if (r_dot_v > 0) { //intensity += light_int * (float)Math.Pow(r_dot_v / (length(vec_r) * length_v), specular); intensity.X += tr * light.r_intensity * (float)Math.Pow(r_dot_v / (length(vec_r) * length_v), specular); intensity.Y += tr * light.g_intensity * (float)Math.Pow(r_dot_v / (length(vec_r) * length_v), specular); intensity.Z += tr * light.b_intensity * (float)Math.Pow(r_dot_v / (length(vec_r) * length_v), specular); } } } } return(intensity); }
public static bool generate_Polyhedron(SdoGeometry geom, out Polyhedron pH) { List <double> pointCoordList = new List <double>(); List <int> coordIndexList = new List <int>(); int[] elInfo = geom.ElemArrayOfInts; double[] ordArray = geom.OrdinatesArrayOfDoubles; if (ordArray.Length == 0) { // An empty data (should not come here, but in some cases it may happen when there is bad data) pH = null; return(false); } int eInfoIdx = 0; // Index on Element Info array int vertIdx = 0; // new Index for the index to the vertex coordinate lists Point3D v = new Point3D(); Point3D v1 = new Point3D(); List <int> noFaceVertList = new List <int>(); // First loop: loop for lump while (eInfoIdx < elInfo.Length) { // advance to the 6th array in the element info to get the number of faces eInfoIdx += 5; int noFace = elInfo[eInfoIdx]; eInfoIdx += 1; // Advance to the first face offset // second loop for the number of faces inside a lump for (int f = 0; f < noFace; f++) { bool vert = true; int vcount = 0; int fIdx = elInfo[eInfoIdx]; while (vert) { if (vcount == 0) { v1.X = ordArray[fIdx - 1]; // -1 because the index starts at no 1 v1.Y = ordArray[fIdx]; v1.Z = ordArray[fIdx + 1]; pointCoordList.Add(v1.X); pointCoordList.Add(v1.Y); pointCoordList.Add(v1.Z); coordIndexList.Add(vertIdx * 3); vertIdx++; vcount++; fIdx += 3; continue; } v.X = ordArray[fIdx - 1]; v.Y = ordArray[fIdx]; v.Z = ordArray[fIdx + 1]; if (Point3D.Equals(v, v1)) { // We are at the end of the vertex list. Oracle SDO repeat the last point as the first point, we can skip this for X3D vert = false; eInfoIdx += 3; noFaceVertList.Add(vcount); // List of no of vertices in each individual face continue; } pointCoordList.Add(v.X); pointCoordList.Add(v.Y); pointCoordList.Add(v.Z); coordIndexList.Add(vertIdx * 3); fIdx += 3; vertIdx++; vcount++; } } } // pH = new Polyhedron(PolyhedronFaceTypeEnum.TriangleFaces, true, pointCoordList, coordIndexList, null); pH = new Polyhedron(PolyhedronFaceTypeEnum.ArbitraryFaces, true, pointCoordList, coordIndexList, noFaceVertList); return(true); }
protected Parallelepiped(Polyhedron isParallelepiped) : base(isParallelepiped) { }