/// <summary> /// Finds the intersection of two circles /// </summary> /// <param name="center1">Center of the first circle</param> /// <param name="center2">Center of the second circle</param> /// <param name="norm1">Normal direction of theh first circle</param> /// <param name="norm2">Normal direction of the second circle</param> /// <param name="r1">radius of circle 1</param> /// <param name="r2">radisu of circle 2</param> /// <returns></returns> internal static intersectionFigData CircleCircleIntersection(Vector3 center1, Vector3 center2, Vector3 norm1, Vector3 norm2, float r1, float r2) { //begin by finding the circle of intersection of two spheres with same center and radius intersectionFigData circleFromSpheres = SphereSphereIntersection(center1, center2, r1, r2); circleFromSpheres.printFigDataToDebug(); Vector3 q = circleFromSpheres.vectordata[0]; //Debug.Log(q); Vector3 nu = circleFromSpheres.vectordata[1]; //Debug.Log(q); float r = circleFromSpheres.floatdata[0]; //Debug.Log(r); //intersection of the plane defined by the first circle and the plane defined by the circle producted in the sphere sphere intersection. intersectionFigData data2 = PlanePlaneIntersection(q, nu, center1, norm1); Vector3[] lineData = data2.vectordata; //intersection of the line from plane plane and the circle formt he sphere sphere. intersectionFigData data3 = CircleLineIntersection(lineData[0], lineData[1], q, nu, r); data3.printFigDataToDebug(); return(data3); }
/// <summary> /// Finds the intersection between two planes /// </summary> /// <param name="pos1">Point on plane 1</param> /// <param name="norm1">Normal direction of plane1</param> /// <param name="pos2">Point on plane 2</param> /// <param name="norm2">Normal direction of plane 2</param> /// <returns></returns> internal static intersectionFigData PlanePlaneIntersection(Vector3 pos1, Vector3 norm1, Vector3 pos2, Vector3 norm2) { Vector3 lineDirection = Vector3.Cross(norm1, norm2); //instead find a line on the plane1 that intersects plane 2 Vector3 crossInput = Vector3.right; if (Vector3.Cross(crossInput, norm1).magnitude == 0) { crossInput = Vector3.up; } Vector3 tLineDir = Vector3.Cross(crossInput, norm1); if (Vector3.Dot(tLineDir, norm2) == 0) { crossInput = Vector3.forward; tLineDir = Vector3.Cross(crossInput, norm1); } //then use line line intersectionFigData figDataTemp = LinePlaneIntersection(pos1, tLineDir, pos2, norm2); figDataTemp.printFigDataToDebug(); if (lineDirection.magnitude > 0 && figDataTemp.figtype == GeoObjType.point) { Vector3 linePosition = figDataTemp.vectordata[0]; return(new intersectionFigData { vectordata = new Vector3[2] { linePosition, lineDirection }, figtype = GeoObjType.line }); } else { return(new intersectionFigData { figtype = GeoObjType.none }); } }