Exemplo n.º 1
0
        public static Double AngleBetween(IVector3D vector1, IVector3D vector2)
        {
            Double dot   = IVector3D.Dot(vector1, vector2);
            Double m1    = Math.Sqrt((vector1.X * vector1.X) + (vector1.Y * vector1.Y) + (vector1.Z * vector1.Z));
            Double m2    = Math.Sqrt((vector2.X * vector2.X) + (vector2.Y * vector2.Y) + (vector2.Z * vector2.Z));
            Double angle = Math.Acos(dot / (m1 * m2));

            if (Double.IsNaN(angle))
            {
                angle = (double)0;
            }
            return(angle);
        }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
0
 /// <summary>
 /// Return the cosine dihedral angles among pairs of two-dimensional elements incident to the given edge.
 /// More than one dihedral angle can be returned since the data structure supports non-manifold meshes.
 /// </summary>
 /// <param name="vKey1"></param>
 /// <param name="vKey2"></param>
 /// <returns></returns>
 public double[] ComputeEdgeCosDihedralAngle(int vKey1, int vKey2)
 {
     int[]    eKey = GetEdgeIncidentElements(vKey1, vKey2);
     double[] dA   = new double[0];
     if (eKey.Length > 1)
     {
         IVector3D n1, n2, p1, p2;
         double    d;
         int       count = eKey.Length - 1;
         int       next_i;
         if (eKey.Length > 2)
         {
             count = eKey.Length;
         }
         dA = new double[count];
         for (int i = 0; i < count; i++)
         {
             next_i = i + 1;
             if (i == eKey.Length - 1)
             {
                 next_i = 0;
             }
             ComputeTwoDimensionalElementNormal(eKey[i], out n1, out p1);
             ComputeTwoDimensionalElementNormal(eKey[next_i], out n2, out p2);
             d = IVector3D.Dot(n1, n2);
             if (d > 1)
             {
                 d = 1;
             }
             else if (d < -1)
             {
                 d = -1;
             }
             dA[i] = d;
         }
     }
     return(dA);
 }
Exemplo 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);
        }