Example #1
0
        //s1,s2,s3で構成される三角形とt1,t2,t3が相似な三角形であるとき、、s1とs2の線とt1とt1を対応する線分である場合のt3の点を返す
        public static LDPoint getSimilarityTrianglePoint(LDPoint _s0, LDPoint _s1, LDPoint _s2, LDPoint _t0, LDPoint _t1)
        {
            LDVector2 s0 = new LDVector2(_s0);
            LDVector2 s1 = new LDVector2(_s1);
            LDVector2 s2 = new LDVector2(_s2);
            LDVector2 t0 = new LDVector2(_t0);
            LDVector2 t1 = new LDVector2(_t1);

            LDVector2 ss2 = s2 + t0 - s0;
            float angle = (float)LDMathUtil.getAngle(s1 - s0, t1 - t0);
            LDPoint sss2 = LDMathUtil.rotatePoint(_t0, ss2.toPoint(), -angle);
            LDVector2 v_s = s1 - s0;
            LDVector2 v_t = t1 - t0;
            float scale = v_t.length() / v_s.length();
            LDPoint t2 = LDMathUtil.scalePoint(_t0, sss2, scale);
            return t2;
        }
Example #2
0
        //s1,s2,s3で構成される三角形とt1,t2,t3が相似な三角形であるとき、、s1とs2の線とt1とt1を対応する線分である場合のt3の点を返す
        public static LDPoint getSimilarityTrianglePoint(LDPoint _s0, LDPoint _s1, LDPoint _s2, LDPoint _t0, LDPoint _t1)
        {
            LDVector2 s0 = new LDVector2(_s0);
            LDVector2 s1 = new LDVector2(_s1);
            LDVector2 s2 = new LDVector2(_s2);
            LDVector2 t0 = new LDVector2(_t0);
            LDVector2 t1 = new LDVector2(_t1);

            LDVector2 ss2   = s2 + t0 - s0;
            float     angle = (float)LDMathUtil.getAngle(s1 - s0, t1 - t0);
            LDPoint   sss2  = LDMathUtil.rotatePoint(_t0, ss2.toPoint(), -angle);
            LDVector2 v_s   = s1 - s0;
            LDVector2 v_t   = t1 - t0;
            float     scale = v_t.length() / v_s.length();
            LDPoint   t2    = LDMathUtil.scalePoint(_t0, sss2, scale);

            return(t2);
        }
Example #3
0
        //点p1 ,p2 ,targetで構成される三角形で、traget点での角度が鈍角か判定
        public static bool isObtuseAngle(LDPoint p1, LDPoint p2, LDPoint target)
        {
            LDVector2 a = new LDVector2(p1);
            LDVector2 b = new LDVector2(p2);
            LDVector2 c = new LDVector2(target);


            LDVector2 ab = a - b;
            LDVector2 bc = b - c;
            LDVector2 ca = c - a;

            if (LDVector2.dotProduct(bc, ca) < 0)
            {
                return(true);
            }

            return(false);
        }
Example #4
0
        public static LDPolygon getHugeTriangle(LDRect rect)
        {
            Debug.Assert(rect.left() < rect.right());
            Debug.Assert(rect.top() < rect.bottom());

            // 1) 与えられた矩形を包含する円を求める
            //      円の中心 c = 矩形の中心
            //      円の半径 r = |p - c| + ρ
            //    ただし、pは与えられた矩形の任意の頂点
            //    ρは任意の正数
            LDVector2 center=new LDVector2(rect.center());
            LDVector2 topLeft=new LDVector2(rect.topLeft());
            float radius = center.distanceToPoint(topLeft);

            radius += 1.0f;//適当に大きくする

            // 2) その円に外接する正三角形を求める
            LDCircle circle=new LDCircle(center.toPoint(), radius);
            return circle.getCircumscribedTriangle();
        }
Example #5
0
        public static LDPolygon getHugeTriangle(LDRect rect)
        {
            Debug.Assert(rect.left() < rect.right());
            Debug.Assert(rect.top() < rect.bottom());

            // 1) 与えられた矩形を包含する円を求める
            //      円の中心 c = 矩形の中心
            //      円の半径 r = |p - c| + ρ
            //    ただし、pは与えられた矩形の任意の頂点
            //    ρは任意の正数
            LDVector2 center  = new LDVector2(rect.center());
            LDVector2 topLeft = new LDVector2(rect.topLeft());
            float     radius  = center.distanceToPoint(topLeft);

            radius += 1.0f;//適当に大きくする

            // 2) その円に外接する正三角形を求める
            LDCircle circle = new LDCircle(center.toPoint(), radius);

            return(circle.getCircumscribedTriangle());
        }
Example #6
0
        //点p1 ,p2 ,p3 で構成される三角形が鈍角三角形か判定する
        public static bool isObtuseTriangle(LDPoint p1, LDPoint p2, LDPoint p3)
        {
            LDVector2 __a = new LDVector2(p1);
            LDVector2 __b = new LDVector2(p2);
            LDVector2 __c = new LDVector2(p3);


            LDVector2 _a = __a - __b;
            LDVector2 _b = __b - __c;
            LDVector2 _c = __c - __a;

            //良く考えたら三角形全部の角度調べるだけでよかった。
            if (LDVector2.dotProduct(_a, _b) < 0)
            {
                return(true);
            }
            if (LDVector2.dotProduct(_a, _c) < 0)
            {
                return(true);
            }
            if (LDVector2.dotProduct(_b, _c) < 0)
            {
                return(true);
            }

            return(false);

            //	float a=_a.length();
            //	float b=_b.length();
            //	float c=_c.length();
            //	int longestIndex;
            //	if ( a>=b  && a >=c )
            //	{
            //		longestIndex=0;
            //	}
            //	else if ( b >=a &&b >=c )
            //	{
            //		longestIndex=1;
            //	}
            //	else
            //	{
            //		longestIndex=2;
            //	}

            //	if ( longestIndex==0 )
            //	{
            //		if ( a*a<=b*b+c*c )
            //		{
            //			return false;
            //		}
            //		return true;
            //	}
            //	if ( longestIndex==1 )
            //	{
            //		if ( b*b<=a*a+c*c )
            //		{
            //			return false;
            //		}
            //		return true;
            //	}
            //	if ( longestIndex==2 )
            //	{
            //		if ( c*c<=b*b+a*a )
            //		{
            //			return false;
            //		}
            //		return true;
            //	}
            //	//ここまでのどこかに引っかかるはず 引っかからなかったらこの関数のどこかにバグがあるはず
            //	Debug.Assert( !" error" );
            //	return false;
        }
Example #7
0
        //点p1 ,p2 ,p3 で構成される三角形が鈍角三角形か判定する
        public static bool isObtuseTriangle(LDPoint p1, LDPoint p2, LDPoint p3)
        {
            LDVector2 __a=new LDVector2(p1);
            LDVector2 __b=new LDVector2(p2);
            LDVector2 __c=new LDVector2(p3);

            LDVector2 _a = __a - __b;
            LDVector2 _b = __b - __c;
            LDVector2 _c = __c - __a;
            //良く考えたら三角形全部の角度調べるだけでよかった。
            if (LDVector2.dotProduct(_a, _b) < 0)
                return true;
            if (LDVector2.dotProduct(_a, _c) < 0)
                return true;
            if (LDVector2.dotProduct(_b, _c) < 0)
                return true;

            return false;

            //	float a=_a.length();
            //	float b=_b.length();
            //	float c=_c.length();
            //	int longestIndex;
            //	if ( a>=b  && a >=c )
            //	{
            //		longestIndex=0;
            //	}
            //	else if ( b >=a &&b >=c )
            //	{
            //		longestIndex=1;
            //	}
            //	else
            //	{
            //		longestIndex=2;
            //	}

            //	if ( longestIndex==0 )
            //	{
            //		if ( a*a<=b*b+c*c )
            //		{
            //			return false;
            //		}
            //		return true;
            //	}
            //	if ( longestIndex==1 )
            //	{
            //		if ( b*b<=a*a+c*c )
            //		{
            //			return false;
            //		}
            //		return true;
            //	}
            //	if ( longestIndex==2 )
            //	{
            //		if ( c*c<=b*b+a*a )
            //		{
            //			return false;
            //		}
            //		return true;
            //	}
            //	//ここまでのどこかに引っかかるはず 引っかからなかったらこの関数のどこかにバグがあるはず
            //	Debug.Assert( !" error" );
            //	return false;
        }
Example #8
0
        //点p1 ,p2 ,targetで構成される三角形で、traget点での角度が鈍角か判定
        public static bool isObtuseAngle(LDPoint p1, LDPoint p2, LDPoint target)
        {
            LDVector2 a = new LDVector2(p1);
            LDVector2 b = new LDVector2(p2);
            LDVector2 c = new LDVector2(target);

            LDVector2 ab = a - b;
            LDVector2 bc = b - c;
            LDVector2 ca = c - a;

            if (LDVector2.dotProduct(bc, ca) < 0)
                return true;

            return false;
        }