获取实际的线段

时间:2011-08-10 07:50:36

标签: c# .net algorithm 3d

由于c#中没有3D矩形,我在此链接http://www.koders.com/csharp/fid8BE50D1ADB6857150794BF12D643BA1739EC3264.aspx中使用了平面和向量函数来表示3D中的矩形(有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(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));



    }

我得到的线方向是无限的,而代表矩形的平面是有限的,因为它们是矩形,如何得到实际的交叉线段,该函数返回任意两点(FirstPoint,SecondPoint),但是而不是交叉线的实际终点

0 个答案:

没有答案