public dPoint CircleCenter(Vector3 p1, Vector3 p2, Vector3 p3) { // Funkcja licząca położenie środka okręgu dPoint point = new dPoint(); point.x = 0.5 * ((p2.X * p2.X * p3.Y + p2.Y * p2.Y * p3.Y - p1.X * p1.X * p3.Y + p1.X * p1.X * p2.Y - p1.Y * p1.Y * p3.Y + p1.Y * p1.Y * p2.Y + p1.Y * p3.X * p3.X + p1.Y * p3.Y * p3.Y - p1.Y * p2.X * p2.X - p1.Y * p2.Y * p2.Y - p2.Y * p3.X * p3.X - p2.Y * p3.Y * p3.Y) / (p1.Y * p3.X - p1.Y * p2.X - p2.Y * p3.X - p3.Y * p1.X + p3.Y * p2.X + p2.Y * p1.X)); point.y = 0.5 * ((-p1.X * p3.X * p3.X - p1.X * p3.Y * p3.Y + p1.X * p2.X * p2.X + p1.X * p2.Y * p2.Y + p2.X * p3.X * p3.X + p2.X * p3.Y * p3.Y - p2.X * p2.X * p3.X - p2.Y * p2.Y * p3.X + p1.X * p1.X * p3.X - p1.X * p1.X * p2.X + p1.Y * p1.Y * p3.X - p1.Y * p1.Y * p2.X) / (p1.Y * p3.X - p1.Y * p2.X - p2.Y * p3.X - p3.Y * p1.X + p3.Y * p2.X + p2.Y * p1.X)); return(point); }
public double Length(dPoint pkt_1, dPoint pkt_2) { return(Math.Sqrt(Math.Pow(pkt_2.x - pkt_1.x, 2) + Math.Pow(pkt_2.y - pkt_1.y, 2))); }
public void rysuj_troj(DxfDocument dxf, Iglica[] iglice) { int punkty_x, punkty_y; punkty_x = Convert.ToInt16(tb_dlugosc.Text) * Convert.ToInt16(1 / 0.01); punkty_y = Convert.ToInt16(tb_szerokosc.Text) * Convert.ToInt16(1 / 0.01); double[] x = new double[punkty_x + 1]; double[] y = new double[punkty_y + 1]; double[,] siatka = new double[punkty_x + 1, punkty_y + 1]; if (Vertices.Count > 2) { //Do triangulation List <Triangulator.Geometry.Triangle> tris = Triangulator.Delauney.Triangulate(Vertices); // Draw the created triangles punkty_x = tris.Count(); foreach (Triangulator.Geometry.Triangle t in tris) { Vector3 pk_1 = new Vector3(); Vector3 pk_2 = new Vector3(); Vector3 pk_3 = new Vector3(); double epsilon = 0.01; // g.DrawLine(myPen, (float)Vertices[t.p1].X, (float)Vertices[t.p1].Y, (float)Vertices[t.p2].X, (float)Vertices[t.p2].Y); // g.DrawLine(myPen, (float)Vertices[t.p2].X, (float)Vertices[t.p2].Y, (float)Vertices[t.p3].X, (float)Vertices[t.p3].Y); // g.DrawLine(myPen, (float)Vertices[t.p1].X, (float)Vertices[t.p1].Y, (float)Vertices[t.p3].X, (float)Vertices[t.p3].Y); pk_1 = new Vector3((float)Vertices[t.p1].X, (float)Vertices[t.p1].Y, 0); pk_2 = new Vector3((float)Vertices[t.p2].X, (float)Vertices[t.p2].Y, 0); pk_3 = new Vector3((float)Vertices[t.p3].X, (float)Vertices[t.p3].Y, 0); for (int i = 0; i < listBox.Items.Count; i++) { if ((Math.Abs(Vertices[t.p1].X - iglice[i].X) < epsilon) & (Math.Abs(Vertices[t.p1].Y - iglice[i].Y) < epsilon)) { pk_1 = new Vector3((float)Vertices[t.p1].X, (float)Vertices[t.p1].Y, iglice[i].wysokosc); } if ((Math.Abs(Vertices[t.p2].X - iglice[i].X) < epsilon) & (Math.Abs(Vertices[t.p2].Y - iglice[i].Y) < epsilon)) { pk_2 = new Vector3((float)Vertices[t.p2].X, (float)Vertices[t.p2].Y, iglice[i].wysokosc); } if ((Math.Abs(Vertices[t.p3].X - iglice[i].X) < epsilon) & (Math.Abs(Vertices[t.p3].Y - iglice[i].Y) < epsilon)) { pk_3 = new Vector3((float)Vertices[t.p3].X, (float)Vertices[t.p3].Y, iglice[i].wysokosc); } } dPoint pk_4 = new dPoint(); dPoint pk_5 = new dPoint(); pk_5.x = pk_1.X; pk_5.y = pk_1.Y; pk_4 = pk_4.CircleCenter(pk_1, pk_2, pk_3); Vector3 pk_6 = new Vector3(); pk_6 = GetCen(pk_1, pk_2, pk_3); Vector2 pk_7 = new Vector2(pk_6.X, pk_6.Y); netDxf.Entities.Line ln_1 = new netDxf.Entities.Line(pk_1, pk_2); netDxf.Entities.Circle circle_1 = new netDxf.Entities.Circle(pk_6, Math.Sqrt(Math.Pow(pk_1.X - pk_6.X, 2) + Math.Pow(pk_1.Y - pk_6.Y, 2) + Math.Pow(pk_1.Z - pk_6.Z, 2))); // dxf.AddEntity(circle_1); //dxf.AddEntity(ln_1); ln_1 = new netDxf.Entities.Line(pk_2, pk_3); //dxf.AddEntity(ln_1); ln_1 = new netDxf.Entities.Line(pk_1, pk_3); //dxf.AddEntity(ln_1); wylicz_punkty_2(dxf, pk_1, pk_2, pk_3, pk_6, ref siatka, ref x, ref y); } Contour(dxf, siatka, x, y, kontury); } }