public static Vector3d RotationRodriguesMethod(Vector3d spinAxis, Vector3d v, double cost)
        {
            //double cost = Math.Cos(angle);
            double sint = Math.Pow(1 - cost * cost, 0.5);

            spinAxis = spinAxis.Normalize();
            return(v * cost +
                   spinAxis.Cross(v) * sint +
                   spinAxis * spinAxis.Dot(v) * (1 - cost));
        }
Beispiel #2
0
 public Plane(Vector3d p, Vector3d n)
 {
     pt = p;
     nv = n.Normalize();
 }
 /*s is the \sigma*/
 private void FilterFaceNormals(double s, int iterations)
 {
     // -- precompute normals based on NII, as a smoothing step --
     int n = mesh.FaceCount; double denominator  = s*s*2;
     old_normals = mesh.FaceNormal.Clone() as double[];
     new_normals = new double[n*3];
     for (int k = 0; k < iterations; ++k)
     {
         for (int i = 0; i < n; ++i)
         {
             // -- get two-ring neighbors
             Set<int> nbrs = this.neighbors[i]; nbrs.Remove(i);
             int count = nbrs.Count, b = i * 3;
             Vector3d ni = new Vector3d(mesh.FaceNormal, b);
             Vector3d nn = new Vector3d();
             foreach (int f in nbrs)
             {
                 Vector3d nj = new Vector3d(mesh.FaceNormal, f * 3);
                 double d = (ni - nj).Length();
                 double w = Math.Exp(-d * d / denominator);
                 nn = nn + w * nj;
             }
             nn = nn.Normalize();
             new_normals[b] = nn.x;
             new_normals[b + 1] = nn.y;
             new_normals[b + 2] = nn.z;
         }
         //mesh.FaceNormal = new_normals.Clone() as double[];
     }
 }
 public void ComputeVertexNormal()
 {
     Array.Clear(vertexNormal, 0, vertexNormal.Length);
     for (int i=0,j=0; i<faceCount; i++,j+=3)
     {
         int c1 = faceIndex[j] * 3;
         int c2 = faceIndex[j+1] * 3;
         int c3 = faceIndex[j+2] * 3;
         vertexNormal[c1] += faceNormal[j];
         vertexNormal[c2] += faceNormal[j];
         vertexNormal[c3] += faceNormal[j];
         vertexNormal[c1+1] += faceNormal[j+1];
         vertexNormal[c2+1] += faceNormal[j+1];
         vertexNormal[c3+1] += faceNormal[j+1];
         vertexNormal[c1+2] += faceNormal[j+2];
         vertexNormal[c2+2] += faceNormal[j+2];
         vertexNormal[c3+2] += faceNormal[j+2];
     }
     for (int i=0,j=0; i<vertexCount; i++,j+=3)
     {
         Vector3d n = new Vector3d(vertexNormal, j);
         n = n.Normalize();
         vertexNormal[j] = n.x;
         vertexNormal[j+1] = n.y;
         vertexNormal[j+2] = n.z;
     }
 }