//масштабирование public void scale(double ind_scale) { for (int i = 0; i < vertices.Count; i++) { PointPol pp = vertices[i].scale(ind_scale); vertices[i] = pp; } }
//поворот //axis == 0 => поворот вокруг OX //axis == 1 => поворот вокруг OY //axis == 2 => поворот вокруг OZ public void rotation(int axis, double cos, double sin) { center = center.roration(axis, cos, sin); for (int i = 0; i < vertices.Count; i++) { PointPol pp = vertices[i].roration(axis, cos, sin); vertices[i] = pp; } }
public PointPol rotate(Edge direction, double angle, double a, double b, double c) { double phi = Math.PI / 360 * angle; PointPol p = shift(-a, -b, -c); double x1 = direction.P1.X; double y1 = direction.P1.Y; double z1 = direction.P1.Z; double x2 = direction.P2.X; double y2 = direction.P2.Y; double z2 = direction.P2.Z; double vecx = x2 - x1; double vecy = y2 - y1; double vecz = z2 - z1; double len = Math.Sqrt(vecx * vecx + vecy * vecy + vecz * vecz); double l = vecx / len; double m = vecy / len; double n = vecz / len; double[,] transfer = new double[4, 4] { { l *l + Math.Cos(phi) * (1 - l * l), l *(1 - Math.Cos(phi)) * m + n * Math.Sin(phi), l *(1 - Math.Cos(phi)) * n - m * Math.Sin(phi), 0 }, { l *(1 - Math.Cos(phi)) * m - n * Math.Sin(phi), m *m + Math.Cos(phi) * (1 - m * m), m *(1 - Math.Cos(phi)) * n + l * Math.Sin(phi), 0 }, { l *(1 - Math.Cos(phi)) * n + m * Math.Sin(phi), m *(1 - Math.Cos(phi)) * n - l * Math.Sin(phi), n *n + Math.Cos(phi) * (1 - n * n), 0 }, { 0, 0, 0, 1 } }; var t1 = _form.matrix_multiplication(p.getP(), transfer); t1 = _form.matrix_multiplication(t1, transfer); PointPol p2 = translatePol(t1); PointPol p3 = p2.shift(a, b, c); return(p3); }
public Octahedron() { center = new PointPol(_form.pictureBox1.Image.Height / 2, _form.pictureBox1.Image.Height / 2, _form.pictureBox1.Image.Height / 2); vertices = new Dictionary <int, PointPol>(); PointPol a = new PointPol(0, 0, 0, len / 2, 1), b = new PointPol(1, len / 2, 0, 0, 1), c = new PointPol(2, 0, len / 2, 0, 1), d = new PointPol(3, -len / 2, 0, 0, 1), e = new PointPol(4, 0, -len / 2, 0, 1), f = new PointPol(5, 0, 0, -len / 2, 1); //добовляем вершины { vertices[a.index] = a; vertices[b.index] = b; vertices[c.index] = c; vertices[d.index] = d; vertices[e.index] = e; vertices[f.index] = f; } //заполняем ребра { edges3D.Add(new Edge(a.index, b.index)); edges3D.Add(new Edge(a.index, c.index)); edges3D.Add(new Edge(a.index, d.index)); edges3D.Add(new Edge(a.index, e.index)); edges3D.Add(new Edge(f.index, b.index)); edges3D.Add(new Edge(f.index, c.index)); edges3D.Add(new Edge(f.index, d.index)); edges3D.Add(new Edge(f.index, e.index)); edges3D.Add(new Edge(b.index, c.index)); edges3D.Add(new Edge(b.index, e.index)); edges3D.Add(new Edge(d.index, c.index)); edges3D.Add(new Edge(d.index, e.index)); } for (int i = 0; i < 6; i++) { neighbors[i] = new List <int>(); } //заполяем списки смежности { neighbors[a.index].Add(b.index); neighbors[a.index].Add(c.index); neighbors[a.index].Add(d.index); neighbors[a.index].Add(e.index); neighbors[b.index].Add(a.index); neighbors[b.index].Add(f.index); neighbors[b.index].Add(c.index); neighbors[b.index].Add(e.index); neighbors[c.index].Add(a.index); neighbors[c.index].Add(f.index); neighbors[c.index].Add(b.index); neighbors[c.index].Add(d.index); neighbors[d.index].Add(a.index); neighbors[d.index].Add(f.index); neighbors[d.index].Add(c.index); neighbors[d.index].Add(e.index); neighbors[e.index].Add(a.index); neighbors[e.index].Add(f.index); neighbors[e.index].Add(b.index); neighbors[e.index].Add(d.index); neighbors[f.index].Add(b.index); neighbors[f.index].Add(c.index); neighbors[f.index].Add(d.index); neighbors[f.index].Add(e.index); } //заполняем полигоны { List <Edge> e1 = new List <Edge>(); e1.Add(new Edge(a.index, b.index)); e1.Add(new Edge(a.index, c.index)); e1.Add(new Edge(b.index, c.index)); polygons.Add(new Polygon(e1)); e1.Clear(); e1.Add(new Edge(a.index, c.index)); e1.Add(new Edge(a.index, d.index)); e1.Add(new Edge(c.index, d.index)); polygons.Add(new Polygon(e1)); e1.Clear(); e1.Add(new Edge(a.index, d.index)); e1.Add(new Edge(a.index, e.index)); e1.Add(new Edge(d.index, e.index)); polygons.Add(new Polygon(e1)); e1.Clear(); e1.Add(new Edge(a.index, b.index)); e1.Add(new Edge(a.index, e.index)); e1.Add(new Edge(b.index, e.index)); polygons.Add(new Polygon(e1)); e1.Clear(); } }
public Tetrahedron() { center = new PointPol(_form.pictureBox1.Image.Height / 2, _form.pictureBox1.Image.Height / 2, _form.pictureBox1.Image.Height / 2); vertices = new Dictionary <int, PointPol>(); PointPol a = new PointPol(0, len / 2, len / 2, len / 2, 1), b = new PointPol(1, -len / 2, -len / 2, len / 2, 1), c = new PointPol(2, -len / 2, len / 2, -len / 2, 1), d = new PointPol(3, len / 2, -len / 2, -len / 2, 1); //добавляем вершины { vertices[0] = a; vertices[1] = b; vertices[2] = c; vertices[3] = d; } for (int i = 0; i < 4; i++) { neighbors[i] = new List <int>(); } //заполняем списки смежности for (int i = 0; i < 4; ++i) { neighbors[i].Add((i + 1) % 4); neighbors[i].Add((i + 2) % 4); neighbors[i].Add((i + 3) % 4); } //заполняем ребра { edges3D.Add(new Edge(a.index, b.index)); edges3D.Add(new Edge(a.index, c.index)); edges3D.Add(new Edge(a.index, d.index)); edges3D.Add(new Edge(b.index, c.index)); edges3D.Add(new Edge(b.index, d.index)); edges3D.Add(new Edge(d.index, c.index)); } //заполняем полигоны { List <Edge> e1 = new List <Edge>(); e1.Add(new Edge(a.index, b.index)); e1.Add(new Edge(a.index, c.index)); e1.Add(new Edge(b.index, c.index)); polygons.Add(new Polygon(e1)); e1.Clear(); e1.Add(new Edge(a.index, c.index)); e1.Add(new Edge(a.index, d.index)); e1.Add(new Edge(c.index, d.index)); polygons.Add(new Polygon(e1)); e1.Clear(); e1.Add(new Edge(a.index, b.index)); e1.Add(new Edge(a.index, d.index)); e1.Add(new Edge(b.index, d.index)); polygons.Add(new Polygon(e1)); e1.Clear(); e1.Add(new Edge(b.index, c.index)); e1.Add(new Edge(b.index, d.index)); e1.Add(new Edge(c.index, d.index)); polygons.Add(new Polygon(e1)); e1.Clear(); } }
public cube() { center = new PointPol(_form.pictureBox1.Image.Height / 2, _form.pictureBox1.Image.Height / 2, _form.pictureBox1.Image.Height / 2); vertices = new Dictionary <int, PointPol>(); //у точки без индекса z меньше PointPol a = new PointPol(0, len / 2, len / 2, -len / 2, 1), a1 = new PointPol(1, len / 2, len / 2, len / 2, 1), b = new PointPol(2, -len / 2, len / 2, -len / 2, 1), b1 = new PointPol(3, -len / 2, len / 2, len / 2, 1), c = new PointPol(4, -len / 2, -len / 2, -len / 2, 1), c1 = new PointPol(5, -len / 2, -len / 2, len / 2, 1), d = new PointPol(6, len / 2, -len / 2, -len / 2, 1), d1 = new PointPol(7, len / 2, -len / 2, len / 2, 1); for (int i = 0; i < 8; i++) { neighbors[i] = new List <int>(); } //добавляем вершины { vertices[0] = a; vertices[1] = a1; vertices[2] = b; vertices[3] = b1; vertices[4] = c; vertices[5] = c1; vertices[6] = d; vertices[7] = d1; } //добавляем ребра { edges3D.Add(new Edge(a.index, a1.index)); edges3D.Add(new Edge(a.index, b.index)); edges3D.Add(new Edge(a.index, d.index)); edges3D.Add(new Edge(c.index, c1.index)); edges3D.Add(new Edge(c.index, b.index)); edges3D.Add(new Edge(c.index, d.index)); edges3D.Add(new Edge(b1.index, b.index)); edges3D.Add(new Edge(b1.index, c1.index)); edges3D.Add(new Edge(b1.index, a1.index)); edges3D.Add(new Edge(d1.index, d.index)); edges3D.Add(new Edge(d1.index, c1.index)); edges3D.Add(new Edge(d1.index, a1.index)); } //заполняем списки смежности { //A neighbors[1].Add(0); neighbors[2].Add(0); neighbors[6].Add(0); //A1 neighbors[0].Add(1); neighbors[3].Add(1); neighbors[7].Add(1); // B neighbors[0].Add(2); neighbors[4].Add(2); neighbors[3].Add(2); //B1 neighbors[1].Add(3); neighbors[5].Add(3); neighbors[2].Add(3); // C neighbors[5].Add(4); neighbors[6].Add(4); neighbors[2].Add(4); //C1 neighbors[4].Add(5); neighbors[7].Add(5); neighbors[3].Add(5); //D neighbors[4].Add(6); neighbors[0].Add(6); neighbors[7].Add(6); //D1 neighbors[5].Add(7); neighbors[1].Add(7); neighbors[6].Add(7); } //заполняем полигоны { List <Edge> e1 = new List <Edge>(); e1.Add(new Edge(a.index, b.index)); e1.Add(new Edge(a.index, d.index)); e1.Add(new Edge(c.index, b.index)); e1.Add(new Edge(c.index, d.index)); polygons.Add(new Polygon(e1)); e1.Clear(); e1 = new List <Edge>(); e1.Add(new Edge(a.index, b.index)); e1.Add(new Edge(a.index, a1.index)); e1.Add(new Edge(a1.index, b1.index)); e1.Add(new Edge(b.index, b1.index)); polygons.Add(new Polygon(e1)); e1.Clear(); e1 = new List <Edge>(); e1.Add(new Edge(a.index, d.index)); e1.Add(new Edge(a.index, a1.index)); e1.Add(new Edge(a1.index, d1.index)); e1.Add(new Edge(d.index, d1.index)); polygons.Add(new Polygon(e1)); e1.Clear(); e1 = new List <Edge>(); e1.Add(new Edge(c.index, d.index)); e1.Add(new Edge(c.index, c1.index)); e1.Add(new Edge(c1.index, d1.index)); e1.Add(new Edge(d.index, d1.index)); polygons.Add(new Polygon(e1)); e1.Clear(); e1 = new List <Edge>(); e1.Add(new Edge(c.index, b.index)); e1.Add(new Edge(c.index, c1.index)); e1.Add(new Edge(c1.index, b1.index)); e1.Add(new Edge(b.index, b1.index)); polygons.Add(new Polygon(e1)); e1.Clear(); e1 = new List <Edge>(); e1.Add(new Edge(a1.index, d1.index)); e1.Add(new Edge(c1.index, d1.index)); e1.Add(new Edge(b1.index, c1.index)); e1.Add(new Edge(a1.index, b1.index)); polygons.Add(new Polygon(e1)); e1.Clear(); } }
//отражение public void reflection(int reflec) { center = center.reflection(reflec); }
//смещение public void shift(double x, double y, double z) { center = center.shift(x, y, z); }
//Конструктор. Создается гексаэдр, //обход вершин: A A1 B1 B C C1 D1 D A, где без индексов - основание куба public Polyhedron() { vertices = new List <PointPol>(); var w = _form.pictureBox1.Width / 2; PointPol a = new PointPol(w, len, 0), a1 = new PointPol(w, len, len), b1 = new PointPol(w, 0, len), b = new PointPol(w, 0, 0), c = new PointPol(w + len, 0, 0), c1 = new PointPol(w + len, 0, len), d = new PointPol(w + len, len, 0), d1 = new PointPol(w + len, len, len); neighbors[a] = new List <PointPol>(); neighbors[b] = new List <PointPol>(); neighbors[c] = new List <PointPol>(); neighbors[d] = new List <PointPol>(); neighbors[a1] = new List <PointPol>(); neighbors[b1] = new List <PointPol>(); neighbors[c1] = new List <PointPol>(); neighbors[d1] = new List <PointPol>(); vertices.Add(a); //A neighbors[a1].Add(a); neighbors[b].Add(a); neighbors[d].Add(a); vertices.Add(a1); //A1 neighbors[a].Add(a1); neighbors[b1].Add(a1); neighbors[d1].Add(a1); vertices.Add(b1); //B1 neighbors[a1].Add(b1); neighbors[c1].Add(b1); neighbors[b].Add(b1); vertices.Add(b); // B neighbors[a].Add(b); neighbors[c].Add(b); neighbors[b1].Add(b); vertices.Add(c); // C neighbors[c1].Add(c); neighbors[d].Add(c); neighbors[b].Add(c); vertices.Add(c1);//C1 neighbors[c].Add(c1); neighbors[d1].Add(c1); neighbors[b1].Add(c1); vertices.Add(d1);//D1 neighbors[c1].Add(d1); neighbors[a1].Add(d1); neighbors[d].Add(d1); vertices.Add(d);//D neighbors[c].Add(d); neighbors[a].Add(d); neighbors[d1].Add(d); List <Edge> e1 = new List <Edge>(); e1.Add(new Edge(a, b)); e1.Add(new Edge(a, d)); e1.Add(new Edge(c, b)); e1.Add(new Edge(c, d)); polygons.Add(new Polygon(e1)); e1.Clear(); e1 = new List <Edge>(); e1.Add(new Edge(a, b)); e1.Add(new Edge(a, a1)); e1.Add(new Edge(a1, b1)); e1.Add(new Edge(b, b1)); polygons.Add(new Polygon(e1)); e1.Clear(); e1 = new List <Edge>(); e1.Add(new Edge(a, d)); e1.Add(new Edge(a, a1)); e1.Add(new Edge(a1, d1)); e1.Add(new Edge(d, d1)); polygons.Add(new Polygon(e1)); e1.Clear(); e1 = new List <Edge>(); e1.Add(new Edge(c, d)); e1.Add(new Edge(c, c1)); e1.Add(new Edge(c1, d1)); e1.Add(new Edge(d, d1)); polygons.Add(new Polygon(e1)); e1.Clear(); e1 = new List <Edge>(); e1.Add(new Edge(c, b)); e1.Add(new Edge(c, c1)); e1.Add(new Edge(c1, b1)); e1.Add(new Edge(b, b1)); polygons.Add(new Polygon(e1)); e1.Clear(); e1 = new List <Edge>(); e1.Add(new Edge(a1, d1)); e1.Add(new Edge(c1, d1)); e1.Add(new Edge(b1, c1)); e1.Add(new Edge(a1, b1)); polygons.Add(new Polygon(e1)); e1.Clear(); }
public Edge(PointPol p1, PointPol p2) { P1 = p1; P2 = p2; }