当前位置: 首页>>代码示例>>C#>>正文


C# Vector3d.normalize方法代码示例

本文整理汇总了C#中Vector3d.normalize方法的典型用法代码示例。如果您正苦于以下问题:C# Vector3d.normalize方法的具体用法?C# Vector3d.normalize怎么用?C# Vector3d.normalize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Vector3d的用法示例。


在下文中一共展示了Vector3d.normalize方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Line

        //----------------------------------CONSTRUCTORS---------------------------------//
        /**
         * Constructor for a line. The line created is the intersection between two planes
         *
         * @param face1 face representing one of the planes
         * @param face2 face representing one of the planes
         */
        public Line(Face face1, Face face2)
        {
            Vector3d normalFace1 = face1.getNormal();
            Vector3d normalFace2 = face2.getNormal();

            //direction: cross product of the faces normals
            direction = new Vector3d();
            direction.cross(normalFace1, normalFace2);

            //if direction lenght is not zero (the planes aren't parallel )...
            if (!(direction.length() < TOL))
            {
                //getting a line point, zero is set to a coordinate whose direction
                //component isn't zero (line intersecting its origin plan)
                point = new Point3d();
                double d1 = -(normalFace1.x * face1.v1.x + normalFace1.y * face1.v1.y + normalFace1.z * face1.v1.z);
                double d2 = -(normalFace2.x * face2.v1.x + normalFace2.y * face2.v1.y + normalFace2.z * face2.v1.z);
                if (Math.Abs(direction.x) > TOL)
                {
                    point.x = 0;
                    point.y = (d2 * normalFace1.z - d1 * normalFace2.z) / direction.x;
                    point.z = (d1 * normalFace2.y - d2 * normalFace1.y) / direction.x;
                }
                else if (Math.Abs(direction.y) > TOL)
                {
                    point.x = (d1 * normalFace2.z - d2 * normalFace1.z) / direction.y;
                    point.y = 0;
                    point.z = (d2 * normalFace1.x - d1 * normalFace2.x) / direction.y;
                }
                else
                {
                    point.x = (d2 * normalFace1.y - d1 * normalFace2.y) / direction.z;
                    point.y = (d1 * normalFace2.x - d2 * normalFace1.x) / direction.z;
                    point.z = 0;
                }
            }

            direction.normalize();
        }
开发者ID:dlannan,项目名称:csg-toolkit,代码行数:46,代码来源:Line.cs

示例2: getNormal

        /**
         * Gets the face normal
         *
         * @return face normal
         */
        public Vector3d getNormal()
        {
            Point3d p1 = v1.getPosition();
            Point3d p2 = v2.getPosition();
            Point3d p3 = v3.getPosition();
            Vector3d xy, xz, normal;

            xy = new Vector3d(p2.x - p1.x, p2.y - p1.y, p2.z - p1.z);
            xz = new Vector3d(p3.x - p1.x, p3.y - p1.y, p3.z - p1.z);

            normal = new Vector3d();
            normal.cross(xy, xz);
            normal.normalize();

            return normal;
        }
开发者ID:dlannan,项目名称:csg-toolkit,代码行数:21,代码来源:Face.cs

示例3: computePointToPointDistance

 //--------------------------------OTHERS----------------------------------------//
 /**
  * Computes the distance from the line point to another point
  *
  * @param otherPoint the point to compute the distance from the line point. The point
  * is supposed to be on the same line.
  * @return points distance. If the point submitted is behind the direction, the
  * distance is negative
  */
 public double computePointToPointDistance(Point3d otherPoint)
 {
     double distance = otherPoint.distance(point);
     Vector3d vec = new Vector3d(otherPoint.x - point.x, otherPoint.y - point.y, otherPoint.z - point.z);
     vec.normalize();
     if (vec.dot(direction) < 0)
     {
         return -distance;
     }
     else
     {
         return distance;
     }
 }
开发者ID:dlannan,项目名称:csg-toolkit,代码行数:23,代码来源:Line.cs

示例4: splitFace


//.........这里部分代码省略.........
                    if ((startVertex == face.v1 && endVertex == face.v2) || (startVertex == face.v2 && endVertex == face.v3) || (startVertex == face.v3 && endVertex == face.v1))
                    {
                        breakFaceInThree(facePos, startPos, endPos, splitEdge);
                    }
                    else
                    {
                        breakFaceInThree(facePos, endPos, startPos, splitEdge);
                    }
                }
                return;
            }

            //______-FACE-______

            //VERTEX-FACE-EDGE
            else if (startType == Segment.VERTEX && endType == Segment.EDGE)
            {
                breakFaceInTwo(facePos, endPos, endVertex);
            }
            //EDGE-FACE-VERTEX
            else if (startType == Segment.EDGE && endType == Segment.VERTEX)
            {
                breakFaceInTwo(facePos, startPos, startVertex);
            }
            //VERTEX-FACE-FACE
            else if (startType == Segment.VERTEX && endType == Segment.FACE)
            {
                breakFaceInThree(facePos, endPos, startVertex);
            }
            //FACE-FACE-VERTEX
            else if (startType == Segment.FACE && endType == Segment.VERTEX)
            {
                breakFaceInThree(facePos, startPos, endVertex);
            }
            //EDGE-FACE-EDGE
            else if (startType == Segment.EDGE && endType == Segment.EDGE)
            {
                breakFaceInThree(facePos, startPos, endPos, startVertex, endVertex);
            }
            //EDGE-FACE-FACE
            else if (startType == Segment.EDGE && endType == Segment.FACE)
            {
                breakFaceInFour(facePos, startPos, endPos, startVertex);
            }
            //FACE-FACE-EDGE
            else if (startType == Segment.FACE && endType == Segment.EDGE)
            {
                breakFaceInFour(facePos, endPos, startPos, endVertex);
            }
            //FACE-FACE-FACE
            else if (startType == Segment.FACE && endType == Segment.FACE)
            {
                Vector3d segmentVector = new Vector3d(startPos.x - endPos.x, startPos.y - endPos.y, startPos.z - endPos.z);

                //if the intersection segment is a point only...
                if (Math.Abs(segmentVector.x) < TOL && Math.Abs(segmentVector.y) < TOL && Math.Abs(segmentVector.z) < TOL)
                {
                    breakFaceInThree(facePos, startPos);
                    return;
                }

                //gets the vertex more lined with the intersection segment
                int linedVertex;
                Point3d linedVertexPos;
                Vector3d vertexVector = new Vector3d(endPos.x - face.v1.x, endPos.y - face.v1.y, endPos.z - face.v1.z);
                vertexVector.normalize();
                double dot1 = Math.Abs(segmentVector.dot(vertexVector));
                vertexVector = new Vector3d(endPos.x - face.v2.x, endPos.y - face.v2.y, endPos.z - face.v2.z);
                vertexVector.normalize();
                double dot2 = Math.Abs(segmentVector.dot(vertexVector));
                vertexVector = new Vector3d(endPos.x - face.v3.x, endPos.y - face.v3.y, endPos.z - face.v3.z);
                vertexVector.normalize();
                double dot3 = Math.Abs(segmentVector.dot(vertexVector));
                if (dot1 > dot2 && dot1 > dot3)
                {
                    linedVertex = 1;
                    linedVertexPos = face.v1.getPosition();
                }
                else if (dot2 > dot3 && dot2 > dot1)
                {
                    linedVertex = 2;
                    linedVertexPos = face.v2.getPosition();
                }
                else
                {
                    linedVertex = 3;
                    linedVertexPos = face.v3.getPosition();
                }

                // Now find which of the intersection endpoints is nearest to that vertex.
                if (linedVertexPos.distance(startPos) > linedVertexPos.distance(endPos))
                {
                    breakFaceInFive(facePos, startPos, endPos, linedVertex);
                }
                else
                {
                    breakFaceInFive(facePos, endPos, startPos, linedVertex);
                }
            }
        }
开发者ID:dlannan,项目名称:csg-toolkit,代码行数:101,代码来源:Object3D.cs


注:本文中的Vector3d.normalize方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。