Пример #1
0
        public static IVector3D CreateUnitVector(IVector3D toVector, IVector3D fromVector)
        {
            IVector3D vector = IVector3D.Sub(toVector, fromVector);

            vector.Norm();
            return(vector);
        }
Пример #2
0
        public static IVector3D VectorWithMagnitude(IVector3D vector, double magnitude)
        {
            IVector3D unit = IVector3D.Norm(vector);

            unit.Mult(magnitude);
            return(unit);
        }
Пример #3
0
        public static IVector3D Norm(IVector3D vector)
        {
            IVector3D unit = new IVector3D(vector);

            unit.Norm();
            return(unit);
        }
Пример #4
0
        public static IVector3D Cross(IVector3D vector1, IVector3D vector2, Boolean unitize)
        {
            IVector3D crossVector;
            double    Cx = vector1.Y * vector2.Z - vector1.Z * vector2.Y;
            double    Cy = vector1.Z * vector2.X - vector1.X * vector2.Z;
            double    Cz = vector1.X * vector2.Y - vector1.Y * vector2.X;

            crossVector = new IVector3D(Cx, Cy, Cz);
            if (unitize)
            {
                crossVector.Norm();
            }
            return(crossVector);
        }
Пример #5
0
        public IVector3D ComputeVertexNormal(int vKey)
        {
            int[]     eKeys = GetVertexIncidentElements(vKey);
            IVector3D normal = new IVector3D();
            IVector3D n, p;

            foreach (int eK in eKeys)
            {
                ComputeTwoDimensionalElementNormal(eK, out n, out p);
                normal += n;
            }
            normal.Norm();
            return(normal);
        }
Пример #6
0
        public IVector3D ComputeVertexNormalAsFaceAreaWeighted(int vKey)
        {
            int[]     eKeys = GetVertexIncidentElements(vKey);
            IVector3D normal = new IVector3D();
            IVector3D n, p;
            double    area;

            foreach (int eK in eKeys)
            {
                ComputeTwoDimensionalElementNormal(eK, out n, out p);
                area    = ComputeTwoDimensionalElementArea(eK);
                n      *= area;
                normal += n;
            }
            normal.Norm();
            return(normal);
        }
Пример #7
0
        public bool ComputeTwoDimensionalElementNormal(int eKey, out IVector3D normal, out IVector3D position)
        {
            IElement e = iM.GetElementWithKey(eKey);

            normal   = new IVector3D();
            position = new IVector3D();
            if (e.TopologicDimension == 2)
            {
                IVector3D        v1, v2;
                ITopologicVertex vv0, vv1, vv2;
                int prev_i, next_i;
                for (int i = 0; i < e.VerticesCount; i++)
                {
                    prev_i = i - 1;
                    if (i == 0)
                    {
                        prev_i = e.VerticesCount - 1;
                    }
                    next_i = i + 1;
                    if (i == e.VerticesCount - 1)
                    {
                        next_i = 0;
                    }

                    vv0 = iM.GetVertexWithKey(e.Vertices[i]);
                    vv1 = iM.GetVertexWithKey(e.Vertices[prev_i]);
                    vv2 = iM.GetVertexWithKey(e.Vertices[next_i]);

                    v1 = vv1.Position - vv0.Position;
                    v2 = vv2.Position - vv0.Position;

                    normal   += v1 * v2;
                    position += vv0.Position;
                }
                normal   /= e.VerticesCount;
                position /= e.VerticesCount;
                normal.Norm();
                return(true);
            }
            return(false);
        }
Пример #8
0
        public bool ComputePolygonNormal(IPoint3D[] polygon, out IVector3D normal, out IVector3D position)
        {
            normal   = new IVector3D();
            position = new IVector3D();
            if (polygon.Length > 2)
            {
                IVector3D v1, v2;
                IVector3D vv0 = new IVector3D();
                IVector3D vv1 = new IVector3D();
                IVector3D vv2 = new IVector3D();
                int       prev_i, next_i;
                for (int i = 0; i < polygon.Length; i++)
                {
                    prev_i = i - 1;
                    if (i == 0)
                    {
                        prev_i = polygon.Length - 1;
                    }
                    next_i = i + 1;
                    if (i == polygon.Length - 1)
                    {
                        next_i = 0;
                    }

                    vv0 += polygon[i];
                    vv1 += polygon[prev_i];
                    vv2 += polygon[next_i];

                    v1 = vv1 - vv0;
                    v2 = vv2 - vv0;

                    normal   += v1 * v2;
                    position += vv0;
                }
                normal   /= polygon.Length;
                position /= polygon.Length;
                normal.Norm();
                return(true);
            }
            return(false);
        }
Пример #9
0
        public bool ComputeTwoDimensionalHalfFacetNormal(int[] hf, out IVector3D normal, out IVector3D position)
        {
            normal   = new IVector3D();
            position = new IVector3D();
            if (hf.Length > 2)
            {
                IVector3D        v1, v2;
                ITopologicVertex vv0, vv1, vv2;
                int prev_i, next_i;
                for (int i = 0; i < hf.Length; i++)
                {
                    prev_i = i - 1;
                    if (i == 0)
                    {
                        prev_i = hf.Length - 1;
                    }
                    next_i = i + 1;
                    if (i == hf.Length - 1)
                    {
                        next_i = 0;
                    }

                    vv0 = iM.GetVertexWithKey(hf[i]);
                    vv1 = iM.GetVertexWithKey(hf[prev_i]);
                    vv2 = iM.GetVertexWithKey(hf[next_i]);

                    v1 = vv1.Position - vv0.Position;
                    v2 = vv2.Position - vv0.Position;

                    normal   += v1 * v2;
                    position += vv0.Position;
                }
                normal   /= hf.Length;
                position /= hf.Length;
                normal.Norm();
                return(true);
            }
            return(false);
        }
Пример #10
0
        public bool ComputeEdgeNormal(int vKey1, int vKey2, out IVector3D normal, out IVector3D center)
        {
            int[] eKeys = GetEdgeIncidentElements(vKey1, vKey2);
            normal  = new IVector3D();
            center  = iM.GetVertexWithKey(vKey1).Position + iM.GetVertexWithKey(vKey2).Position;
            center /= 2;

            if (eKeys.Length == 0)
            {
                return(false);
            }

            foreach (int eK in eKeys)
            {
                IVector3D n, p;
                ComputeTwoDimensionalElementNormal(eK, out n, out p);
                normal += n;
            }
            normal /= eKeys.Length;
            normal.Norm();

            return(true);
        }