Get the actual line Segment
Since there are no 3D rectangle in c# ,I used the plane, and vector function in this link http://www.koders.com/csharp/fid8BE50D1ADB6857150794BF12D643BA1739EC3264.aspx to represent rectange in 3D (have x,y,z)
public Plane(Vector3 point1, Vector3 point2, Vector3 point3) {
a = (point1.y * (point2.z - point3.z)) + (point2.y * (point3.z - point1.z))+ (point3.y * (point1.z - point2.z)) ;
b = (point1.z * (point2.x - point3.x)) + (point2.z * (point3.x - point1.x))+ (point3.z * (point1.x - point2.x)) ;
c = (point1.x * (point2.y - point3.y)) + (point2.x * (point3.y - point1.y)) + (point3.x *(point1.y - point2.y)) ;
d = - (
(point1.x *( (point2.y * point3.z ) - ( point3.y * point2.z) ))
+
(point2.x *( (point3.y * point1.z ) - ( point1.y * point3.z) ))
+
(point3.x *( (point1.y * point2.z ) - ( point2.y * point1.z) ))
); }
public void intersectionSecondTry(Plane SecondOne) {
// Step 1. get the line direction ( true with paxeraview )
//Vector3 LineDirection = Normal.Cross开发者_如何学C(SecondOne.Normal);
float tempX1 = -100 ;
float tempZ1 = ( (SecondOne.b/b)*d - SecondOne.d)/(SecondOne.c - c*SecondOne.b/b) ;
float tempY1 = (-c * tempZ1 -d) / b;
FirstPoint = new Vector3(tempX1, (float.IsNaN(tempY1) ? 0 : tempY1), (float.IsNaN(tempZ1) ? 0 : tempZ1));
float tempX2 = 200 ;
float tempZ2 = ((SecondOne.b / b) * d - SecondOne.d) / (SecondOne.c - c * SecondOne.b / b);
float tempY2 = (-c * tempZ2 - d) / b;
SecondPoint = new Vector3(tempX2, (float.IsNaN(tempY2) ? 0 : tempY2), (float.IsNaN(tempZ2) ? 0 : tempZ2));
}
the line direction I got is infinite while the planes that represent the rectangles are finite because they are rectangles , how to get the actual line segment of intersection , the function return any two points (FirstPoint ,SecondPoint ) on the line , but not the actual end points of line of intersection
精彩评论