Ejemplo n.º 1
0
        /// 点と面との最近接点を算出
        static public float GetClosestPtPosPlane(Vector3 trgPos, GeometryPlane trgPlane, ref Vector3 cPos)
        {
            float num, denom;
            float t;

            /// 法線とレイの1頂点とのベクトルの内積を求める
            num = trgPlane.Nor.Dot(trgPos);

            /// 法線とレイの内積を求める
            denom = trgPlane.Nor.Dot(trgPlane.Nor);

            /// 平面と平行なので交点なし
            if (denom == 0.0f)
            {
                return(-1.0f);
            }

            /// 媒介変数を求める
            t = (-(num + trgPlane.D)) / denom;

            /// 直線の方程式から交点を求める
            cPos.X = trgPos.X + (t * trgPlane.Nor.X);
            cPos.Y = trgPos.Y + (t * trgPlane.Nor.Y);
            cPos.Z = trgPos.Z + (t * trgPlane.Nor.Z);

            return(t);
        }
Ejemplo n.º 2
0
        /// 線分と平面との交点をもとめる
        static private float getRayPlaneCrossPoint(GeometryPlane plane, GeometryLine line, ref Vector3 crossPos)
        {
            float num, denom;
            float t;

            /// 法線とレイの1頂点とのベクトルの内積を求める
            num = plane.Nor.Dot(line.StartPos);

            /// 法線とレイの内積を求める
            denom = plane.Nor.Dot(line.Vec);

            /// 平面と平行なので交点なし
            if (denom == 0.0f)
            {
                return(-1.0f);
            }

            /// 媒介変数を求める
            t = (-(num + plane.D)) / denom;

            /// 直線の方程式から交点を求める
            crossPos.X = line.StartPos.X + (t * line.Vec.X);
            crossPos.Y = line.StartPos.Y + (t * line.Vec.Y);
            crossPos.Z = line.StartPos.Z + (t * line.Vec.Z);

            return(t);
        }
Ejemplo n.º 3
0
 /// コンストラクタ
 public GeometryTriangle()
 {
     this.Plane	= new GeometryPlane();
     this.Pos		= new Vector3[3];
     for( int i=0; i<3; i++ ){
     this.Pos[i] = new Vector3();
     }
 }
Ejemplo n.º 4
0
 /// コンストラクタ
 public GeometryTriangle()
 {
     this.Plane = new GeometryPlane();
     this.Pos   = new Vector3[3];
     for (int i = 0; i < 3; i++)
     {
         this.Pos[i] = new Vector3();
     }
 }
Ejemplo n.º 5
0
 public GeometryTriangle( Vector3 pos1, Vector3 pos2, Vector3 pos3 )
 {
     this.Plane	= new GeometryPlane();
     this.Pos		= new Vector3[3];
     for( int i=0; i<3; i++ ){
     this.Pos[i] = new Vector3();
     }
     Set( pos1, pos2, pos3 );
 }
Ejemplo n.º 6
0
 public GeometryTriangle(Vector3 pos1, Vector3 pos2, Vector3 pos3)
 {
     this.Plane = new GeometryPlane();
     this.Pos   = new Vector3[3];
     for (int i = 0; i < 3; i++)
     {
         this.Pos[i] = new Vector3();
     }
     Set(pos1, pos2, pos3);
 }
Ejemplo n.º 7
0
        /// 線分と平面との交差チェック
        static private bool checkRayCrossPlane(GeometryPlane plane, GeometryLine line)
        {
            float sign1, sign2;

            /// 法線と頂点との位置関係を内積で求める(正:面の正面、負:面の背後)
            sign1 = plane.Nor.Dot(line.StartPos) + plane.D;
            sign2 = plane.Nor.Dot(line.EndPos) + plane.D;

            /// 符合が一致すると平面に対して交差した事にならない
            if ((sign1 > epsilon && sign2 > epsilon) || (sign1 < epsilon && sign2 < epsilon))
            {
                return(false);
            }

            return(true);
        }
Ejemplo n.º 8
0
        /// 線分と平面との交点をもとめる
        private static float getRayPlaneCrossPoint( GeometryPlane plane, GeometryLine line, ref Vector3 crossPos )
        {
            float num, denom;
            float t;

            /// 法線とレイの1頂点とのベクトルの内積を求める
            num	= plane.Nor.Dot( line.StartPos );

            /// 法線とレイの内積を求める
            denom	= plane.Nor.Dot( line.Vec );

            /// 平面と平行なので交点なし
            if( denom == 0.0f ){
            return -1.0f;
            }

            /// 媒介変数を求める
            t = ( -(num + plane.D) ) / denom;

            /// 直線の方程式から交点を求める
            crossPos.X = line.StartPos.X + ( t * line.Vec.X );
            crossPos.Y = line.StartPos.Y + ( t * line.Vec.Y );
            crossPos.Z = line.StartPos.Z + ( t * line.Vec.Z );

            return t;
        }
Ejemplo n.º 9
0
        /// 線分と平面との交差チェック
        private static bool checkRayCrossPlane( GeometryPlane plane, GeometryLine line )
        {
            float sign1, sign2;

            /// 法線と頂点との位置関係を内積で求める(正:面の正面、負:面の背後)
            sign1 = plane.Nor.Dot( line.StartPos ) + plane.D;
            sign2 = plane.Nor.Dot( line.EndPos ) + plane.D;

            /// 符合が一致すると平面に対して交差した事にならない
            if( (sign1 > epsilon && sign2 > epsilon) || (sign1 < epsilon && sign2 < epsilon) ){
            return false;
            }

            return true;
        }
Ejemplo n.º 10
0
        /// 点と面との最近接点を算出
        public static float GetClosestPtPosPlane( Vector3 trgPos, GeometryPlane trgPlane, ref Vector3 cPos )
        {
            float num, denom;
            float t;

            /// 法線とレイの1頂点とのベクトルの内積を求める
            num	= trgPlane.Nor.Dot( trgPos );

            /// 法線とレイの内積を求める
            denom	= trgPlane.Nor.Dot( trgPlane.Nor );

            /// 平面と平行なので交点なし
            if( denom == 0.0f ){
            return -1.0f;
            }

            /// 媒介変数を求める
            t = ( -(num + trgPlane.D) ) / denom;

            /// 直線の方程式から交点を求める
            cPos.X = trgPos.X + ( t * trgPlane.Nor.X );
            cPos.Y = trgPos.Y + ( t * trgPlane.Nor.Y );
            cPos.Z = trgPos.Z + ( t * trgPlane.Nor.Z );

            return t;
        }