Ejemplo n.º 1
0
        public static double AngleBetween(IPoint3D pt1, IPoint3D pt2, IPoint3D origin)
        {
            IVector3D v1    = IVector3D.CreateVector(pt1, origin);
            IVector3D v2    = IVector3D.CreateVector(pt2, origin);
            double    dot   = IVector3D.Dot(v1, v2);
            double    cos   = dot / (v1.Mag() * v2.Mag());
            double    angle = Math.Acos(cos);

            if (Double.IsNaN(angle))
            {
                angle = (double)0;
            }
            return(angle);
        }
Ejemplo n.º 2
0
        public double DistanceTo(IPoint3D pt)
        {
            IVector3D vec = this - pt;

            return(vec.Mag());
        }
Ejemplo n.º 3
0
        public static double Dist(IVector3D vector1, IVector3D vector2)
        {
            IVector3D vec = IVector3D.Sub(vector1, vector2);

            return(vec.Mag());
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Computes the discrete Gaussian curvature as in the paper "Discrete Differential-Geometry Operators for Triangulated
        /// 2-Manifolds" (http://www.cs.caltech.edu/~mmeyer/Publications/diffGeomOps.pdf)
        /// </summary>
        public double ComputesGaussianCurvature(int vKey)
        {
            IVector3D meanCurvatureVector = new IVector3D();

            if (IsNakedVertex(vKey))
            {
                return(0.0);
            }

            IVector3D vect1 = new IVector3D();
            IVector3D vect2 = new IVector3D();
            IVector3D vect3 = new IVector3D();
            double    mixed = 0.0;
            double    gauss = 0.0;

            int[]            nKey = iM.Topology.GetVertexAdjacentVertices(vKey);
            ITopologicVertex v    = iM.GetVertexWithKey(vKey);
            int next_i;

            for (int i = 0; i < nKey.Length; i++)
            {
                next_i = i + 1;
                if (i == nKey.Length - 1)
                {
                    next_i = 0;
                }

                ITopologicVertex p1 = iM.GetVertexWithKey(nKey[i]);
                ITopologicVertex p2 = iM.GetVertexWithKey(nKey[next_i]);
                vect1 = IVector3D.CreateVector(v.Position, p1.Position);
                vect2 = IVector3D.CreateVector(p1.Position, p2.Position);
                vect3 = IVector3D.CreateVector(p2.Position, v.Position);
                double c12 = IVector3D.Dot(vect1, vect2);
                double c23 = IVector3D.Dot(vect2, vect3);
                double c31 = IVector3D.Dot(vect3, vect1);
                vect2 = IVector3D.Cross(vect1, vect3, false);
                double area = 0.5 * vect2.Mag();

                // This angle is obtuse
                if (c31 > 0.0)
                {
                    mixed += 0.5 * area;
                }
                else if (c12 > 0.0 || c23 > 0.0)
                {
                    mixed += 0.25 * area;
                }
                else
                {
                    if (area > 0.0 && area > -1e-9 * (c12 + c23))
                    {
                        mixed -= 0.125 * 0.5 * (c12 * IVector3D.Dot(vect3, vect3) + c23 * IVector3D.Dot(vect1, vect1)) / area;
                    }
                }
                gauss += Math.Abs(Math.Atan2(2.0 * area, -c31));
                vect3 *= c12;
                vect1 *= -c23;
                vect3 += vect1;
                meanCurvatureVector += vect3 * (0.5 / area);
            }

            meanCurvatureVector *= (0.5 / mixed);
            // Discrete gaussian curvature
            return((2.0 * Math.PI - gauss) / mixed);
        }