/// <summary> /// Calculates the intersection point of two given lines in 3D space. /// </summary> /// <param name="plane">Fist line.</param> /// <param name="line">Second line.</param> /// <param name="intersection">Out parameter, true if intersection exists.</param> /// <returns>The point of the intersection.</returns> public static Point3D Intersection(Plane3D plane, Line3D line, out bool intersection) { Point3D point = new Point3D(); Matrix linearEquation = new Matrix(plane, line); linearEquation.ToRREF(); int type = linearEquation.LinearEquationSolutionType(); intersection = false; if (type == 1) //exactly one solution { if (plane.SupportVector.Z + linearEquation.Mtrx[0, 3] * plane.DirectionVectors[0].Z + linearEquation.Mtrx[1, 3] * plane.DirectionVectors[1].Z == line.SupportVector.Z + linearEquation.Mtrx[2, 3] * line.DirectionVector.Z) { intersection = true; point = plane.GetPointAt(linearEquation.Mtrx[0, 3], linearEquation.Mtrx[1, 3]); } } else if (type == -1) //infinite soulutions { intersection = true; point.X = double.NaN; point.Y = double.NaN; point.Z = double.NaN; } return(point); }
/// <summary> /// Checks if two planes are parallel to each other. /// </summary> /// <param name="plane1">First plane.</param> /// <param name="plane2">Second plane.</param> /// <returns></returns> public static bool IsParallel(Plane3D plane1, Plane3D plane2) { return(IsParallel(plane1.NormalVector, plane2.NormalVector)); }
/// <summary> /// Calculates the angle between a plane and a line in radians. /// </summary> /// <param name="plane">A plane.</param> /// <param name="line">A line</param> /// <returns></returns> public static double AngleBetween(Plane3D plane, Line3D line) { return(Math.PI / 2 - AngleBetween(plane.NormalVector, line.DirectionVector)); }
/// <summary> /// Calculates the angle between two planes in radians. /// </summary> /// <param name="plane1">First plane.</param> /// <param name="plane2">Second plane.</param> /// <returns></returns> public static double AngleBetween(Plane3D plane1, Plane3D plane2) { return(AngleBetween(plane1.NormalVector, plane2.NormalVector)); }
/// <summary> /// Calculates the angle between a plane and a vector in radians. /// </summary> /// <param name="plane">First line.</param> /// <param name="vector">Second line.</param> /// <returns></returns> public static double AngleBetween(Plane3D plane, Vect3D vector) { return(Math.PI / 2 - AngleBetween(plane.NormalVector, vector)); }