# Math3d.ClosestPointsOnTwoLines(out UnityEngine.Vector3, out UnityEngine.Vector3, UnityEngine.Vector3, UnityEngine.Vector3, UnityEngine.Vector3, UnityEngine.Vector3)

Here are the examples of the csharp api Math3d.ClosestPointsOnTwoLines(out UnityEngine.Vector3, out UnityEngine.Vector3, UnityEngine.Vector3, UnityEngine.Vector3, UnityEngine.Vector3, UnityEngine.Vector3) taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

## 2 Examples

19 View Source File : Math3d.cs
Project Creator : m969

``````public static void PlaneFrom3Points(out Vector3 planeNormal, out Vector3 planePoint, Vector3 pointA, Vector3 pointB, Vector3 pointC)
{
planeNormal = Vector3.zero;
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;
ClosestPointsOnTwoLines(out planePoint, out temp, middleAB, middleABtoC, middleAC, middleACtoB);
}``````

19 View Source File : Math3d.cs
Project Creator : m969

``````public static bool AreLineSegmentsCrossing(Vector3 pointA1, Vector3 pointA2, Vector3 pointB1, Vector3 pointB2)
{
Vector3 closestPointA;
Vector3 closestPointB;
int sideA;
int sideB;

Vector3 lineVecA = pointA2 - pointA1;
Vector3 lineVecB = pointB2 - pointB1;

bool valid = ClosestPointsOnTwoLines(out closestPointA, out closestPointB, pointA1, lineVecA.normalized, pointB1, lineVecB.normalized);

//lines are not parallel
if(valid)
{
sideA = PointOnWhichSideOfLineSegment(pointA1, pointA2, closestPointA);
sideB = PointOnWhichSideOfLineSegment(pointB1, pointB2, closestPointB);

if((sideA == 0) && (sideB == 0))
{
return true;
}
else
{
return false;
}
}
//lines are parallel
else
{
return false;
}
}``````