Example #1
0
        //Convert a plane defined by 3 points to a plane defined by a vector and a point.
        //The plane point is the middle of the triangle defined by the 3 points.
        public static ExtPlane PlaneFrom3Points(Vector3 pointA, Vector3 pointB, Vector3 pointC)
        {
            Vector3 planeNormal = Vector3.zero;
            Vector3 planePoint  = Vector3.zero;

            //Make two vectors from the 3 input points, originating from point A
            Vector3 AB = pointB - pointA;
            Vector3 AC = pointC - pointA;

            //Calculate the normal
            planeNormal = Vector3.Normalize(Vector3.Cross(AB, AC));

            //Get the points in the middle AB and AC
            Vector3 middleAB = pointA + (AB / 2.0f);
            Vector3 middleAC = pointA + (AC / 2.0f);

            //Get vectors from the middle of AB and AC to the point which is not on that line.
            Vector3 middleABtoC = pointC - middleAB;
            Vector3 middleACtoB = pointB - middleAC;

            //Calculate the intersection between the two lines. This will be the center
            //of the triangle defined by the 3 points.
            //We could use LineLineIntersection instead of ClosestPointsOnTwoLines but due to rounding errors
            //this sometimes doesn't work.
            Vector3 temp;

            ExtLine.ClosestPointsOnTwoLines(out planePoint, out temp, middleAB, middleABtoC, middleAC, middleACtoB);

            return(new ExtPlane(planePoint, planeNormal, true));
        }
Example #2
0
        public ExtLine3d(Vector3 position, Quaternion rotation, Vector3 localScale) : this()
        {
            _position   = position;
            _rotation   = rotation;
            _localScale = localScale;

            _lineLocalPosition = new ExtLine(new Vector3(0, 0, 0.4f), new Vector3(0, 0, -0.4f));
            UpdateMatrix();
        }
Example #3
0
 /// <summary>
 /// Calculates the intersection line segment between 2 lines (not segments).
 /// Returns false if no solution can be found.
 /// </summary>
 /// <returns></returns>
 public static bool CalculateLineLineIntersection3d(ExtLine line1, ExtLine line2, out Vector3 resulmtSegmentPoint1, out Vector3 resultSegmentPoint2)
 {
     return(CalculateLineLineIntersection3d(line1._p1, line1._p2, line2._p1, line2._p2, out resulmtSegmentPoint1, out resultSegmentPoint2));
 }
Example #4
0
 /// <summary>
 /// return percentage (from 0 to 1) of the position of the C vector
 /// </summary>
 public static float GetPercentageInLineFromPosition(ExtLine line, Vector3 c)
 {
     return(GetPercentageInLineFromPosition(line._p1, line._p2, c));
 }
Example #5
0
 /// <summary>
 /// return the point at a given percentage of a line
 /// </summary>
 /// <param name="percentage">0 to 1</param>
 /// <returns></returns>
 public static Vector3 GetPositionInLineFromPercentage(ExtLine line, float percentage)
 {
     return(GetPositionInLineFromPercentage(line._p1, line._p2, percentage));
 }