Esempio n. 1
0
 public static float Orient(Vertex a,
             Vertex b,
             Vertex c)
 {
     Matrix3 m = new Matrix3(a.x, a.y, 1,
                             b.x, b.y, 1,
                             c.x, c.y, 1);
     return m.Determinant();
 }
Esempio n. 2
0
            public bool CircumCircle(List<Vertex> verts, out Vertex center, out float radius)
            {
                // Calculate the circle that passes through 3 coplanar points
                // http://mathworld.wolfram.com/Circle.html

                Vertex p0 = verts[vertices[0]];
                Vertex p1 = verts[vertices[1]];
                Vertex p2 = verts[vertices[2]];

                Matrix3 ma = new Matrix3(p0.x, p0.y, 1,
                                            p1.x, p1.y, 1,
                                            p2.x, p2.y, 1);
                float a = ma.Determinant();
                if (Math.Abs(a) < 1e-5f)
                {
                    center = new Vertex(0, 0);
                    radius = 0;
                    return false;
                }

                Matrix3 md = new Matrix3(p0.x * p0.x + p0.y * p0.y, p0.y, 1,
                                          p1.x * p1.x + p1.y * p1.y, p1.y, 1,
                                          p2.x * p2.x + p2.y * p2.y, p2.y, 1);
                float d = -md.Determinant();

                Matrix3 me = new Matrix3(p0.x * p0.x + p0.y * p0.y, p0.x, 1,
                                          p1.x * p1.x + p1.y * p1.y, p1.x, 1,
                                          p2.x * p2.x + p2.y * p2.y, p2.x, 1);
                float e = me.Determinant();

                Matrix3 mf = new Matrix3(p0.x * p0.x + p0.y * p0.y, p0.x, p0.y,
                                          p1.x * p1.x + p1.y * p1.y, p1.x, p1.y,
                                          p2.x * p2.x + p2.y * p2.y, p2.x, p2.y);
                float f = -mf.Determinant();

                center = new Vertex(-d / (2 * a), -e / (2 * a));
                radius = (float)Math.Sqrt((d * d + e * e) / (4 * a * a) - f / a);

                return true;
            }