예제 #1
0
파일: LDLine.cs 프로젝트: johndpope/math
        /// <summary>
        /// out Upoint 未実装
        /// </summary>
        /// <param name="l"></param>
        /// <param name="point"></param>
        /// <returns></returns>
        public IntersectType intersect(LDLine l, out LDPoint point)
        {
            IntersectType intersect;

            if (MathFunctions.uFuzzyCompare(this.angle(), l.angle()))
            {
                point     = null;
                intersect = IntersectType.NoIntersection;
            }
            else
            {
                LDLine lp12 = new LDLine(this.pt1, l.pt1);
                LDLine lp22 = new LDLine(this.pt1, l.pt2);

                LDLine lp11 = new LDLine(l.pt1, this.pt1);
                LDLine lp21 = new LDLine(l.pt1, this.pt2);

                if (((this.angleTo(lp12) - 180f) * (this.angleTo(lp22) - 180f) < 0) &&
                    ((this.angleTo(lp11) - 180f) * (this.angleTo(lp21) - 180f) < 0))
                {
                    point     = null;
                    intersect = IntersectType.BoundedIntersection;
                }
                else
                {
                    point     = null;
                    intersect = IntersectType.UnboundedIntersection;
                }
            }
            return(intersect);
        }
예제 #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="l"></param>
        /// <param name="point"></param>
        /// <returns></returns>
        public IntersectType intersect(LDLine l, out LDPoint point)
        {
            LDPoint pointA = this.pt1;
            LDPoint pointB = this.pt2;
            LDPoint pointC = l.pt1;
            LDPoint pointD = l.pt2;

            float dBunbo = (pointB.x() - pointA.x())
                           * (pointD.y() - pointC.y())
                           - (pointB.y() - pointA.y())
                           * (pointD.x() - pointC.x());

            if (0 == dBunbo)
            {   // 平行
                point = null;
                return(IntersectType.NoIntersection);
            }

            //ここで交点を導出
            LDPoint vectorAC = pointC - pointA;
            var     dR       = ((pointD.y() - pointC.y()) * vectorAC.x()
                                - (pointD.x() - pointC.x()) * vectorAC.y()) / dBunbo;
            var dS = ((pointB.y() - pointA.y()) * vectorAC.x()
                      - (pointB.x() - pointA.x()) * vectorAC.y()) / dBunbo;

            point = pointA + dR * (pointB - pointA);

            return((new LDRect(pointA, pointB)).contains(point) && (new LDRect(pointC, pointD)).contains(point) ? IntersectType.BoundedIntersection : IntersectType.UnboundedIntersection);

            /*
             * IntersectType intersect;
             * if (MathFunctions.uFuzzyCompare(this.angle(), l.angle()))
             * {
             *  point = null;
             *  intersect = IntersectType.NoIntersection;
             * }
             * else
             * {
             *  LDLine lp12 = new LDLine(this.pt1, l.pt1);
             *  LDLine lp22 = new LDLine(this.pt1, l.pt2);
             *
             *  LDLine lp11 = new LDLine(l.pt1, this.pt1);
             *  LDLine lp21 = new LDLine(l.pt1, this.pt2);
             *
             *  if (((this.angleTo(lp12) - 180f) * (this.angleTo(lp22) - 180f) < 0)
             *      && ((this.angleTo(lp11) - 180f) * (this.angleTo(lp21) - 180f) < 0))
             *  {
             *      point = null;
             *      intersect = IntersectType.BoundedIntersection;
             *  }
             *  else
             *  {
             *      point = null;
             *      intersect = IntersectType.UnboundedIntersection;
             *  }
             * }
             * return intersect;
             */
        }
예제 #3
0
파일: LDLine.cs 프로젝트: johndpope/math
        public void setLength(float len)
        {
            if (this.isNull())
            {
                return;
            }
            LDLine v = this.unitVector();

            this.pt2 = new LDPoint(this.pt1.x() + v.dx() * len, this.pt1.y() + v.dy() * len);
        }
예제 #4
0
파일: LDLine.cs 프로젝트: johndpope/math
        public LDLine unitVector()
        {
            if (this.length() == 0)
            {
                return(this);
            }
            LDLine unit = new LDLine(this);

            unit.setP2(new LDPoint(unit.pt1.x() + unit.dx() / this.length(), unit.pt1.y() + unit.dy() / this.length()));
            return(unit);
        }
예제 #5
0
        public bool isHit(LDPointList form, LDPoint p, float hitRange)
        {
            LDLine l = this.toLine(form);

            LDPoint startPt = l.p1();
            LDPoint endPt   = l.p2();

            //端点から一定の距離内だったら当たり
            if (PointUtil.isHit(startPt, p, hitRange))
            {
                return(true);
            }
            if (PointUtil.isHit(endPt, p, hitRange))
            {
                return(true);
            }


            //点が一直線上にないか確認
            if (TriangleUtil.isTriangle(startPt, endPt, p))
            {
                //鈍角三角形なら判定外
                if (TriangleUtil.isObtuseAngle(startPt, endPt, p))
                {
                    return(false);
                }

                //三角形の面積を算出して、その底面で割れば高さ=線と点の距離
                float distance = TriangleUtil.getTriangleHeight(startPt, endPt, p);

                if (distance <= hitRange)
                {
                    return(true);
                }
                return(false);
            }
            //一直線上にあるが線分外にあるか判定
            LDVector2 ab    = new LDVector2(endPt - startPt);
            LDVector2 ap    = new LDVector2(p - startPt);
            LDVector2 bp    = new LDVector2(p - endPt);
            float     omega = 0.0001f;//NOTE:誤差の基準値 かなり適当に指定

            if (ap.length() + bp.length() > ab.length() + omega)
            {
                return(false);
            }
            return(true);
        }
예제 #6
0
파일: LDLine.cs 프로젝트: johndpope/math
 public LDLine(LDLine line)
 {
     this.pt1 = new LDPoint(line.pt1);
     this.pt2 = new LDPoint(line.pt2);
 }
예제 #7
0
파일: LDLine.cs 프로젝트: johndpope/math
 public float angleTo(LDLine l)
 {
     return(l.angle() - this.angle() >= 0 ? l.angle() - this.angle() : l.angle() - this.angle() + 360);
 }
예제 #8
0
파일: LDLine.cs 프로젝트: KajitaLD/math
 public float angleTo(LDLine l)
 {
     return l.angle() - this.angle() >= 0 ? l.angle() - this.angle() : l.angle() - this.angle() + 360;
 }
예제 #9
0
파일: LDLine.cs 프로젝트: KajitaLD/math
 public LDLine(LDLine line)
 {
     this.pt1 = new LDPoint(line.pt1);
     this.pt2 = new LDPoint(line.pt2);
 }
예제 #10
0
파일: LDLine.cs 프로젝트: KajitaLD/math
 public LDLine unitVector()
 {
     if (this.length() == 0)
     {
         return this;
     }
     LDLine unit = new LDLine(this);
     unit.setP2(new LDPoint(unit.pt1.x() + unit.dx() / this.length(), unit.pt1.y() + unit.dy() / this.length()));
     return unit;
 }
예제 #11
0
파일: LDLine.cs 프로젝트: KajitaLD/math
        /// <summary>
        /// 
        /// </summary>
        /// <param name="l"></param>
        /// <param name="point"></param>
        /// <returns></returns>
        public IntersectType intersect(LDLine l, out LDPoint point)
        {
            LDPoint pointA = this.pt1;
            LDPoint pointB = this.pt2;
            LDPoint pointC = l.pt1;
            LDPoint pointD = l.pt2;

            float dBunbo = (pointB.x() - pointA.x())
                    * (pointD.y() - pointC.y())
                    - (pointB.y() - pointA.y())
                    * (pointD.x() - pointC.x());
            if (0 == dBunbo)
            {   // 平行
                point = null;
                return IntersectType.NoIntersection;
            }

            //ここで交点を導出
            LDPoint vectorAC = pointC - pointA;
            var dR = ((pointD.y() - pointC.y()) * vectorAC.x()
                 - (pointD.x() - pointC.x()) * vectorAC.y()) / dBunbo;
            var dS = ((pointB.y() - pointA.y()) * vectorAC.x()
                 - (pointB.x() - pointA.x()) * vectorAC.y()) / dBunbo;
            point = pointA + dR * (pointB - pointA);

            return (new LDRect(pointA, pointB)).contains(point) && (new LDRect(pointC, pointD)).contains(point) ? IntersectType.BoundedIntersection : IntersectType.UnboundedIntersection;

            /*
            IntersectType intersect;
            if (MathFunctions.uFuzzyCompare(this.angle(), l.angle()))
            {
                point = null;
                intersect = IntersectType.NoIntersection;
            }
            else
            {
                LDLine lp12 = new LDLine(this.pt1, l.pt1);
                LDLine lp22 = new LDLine(this.pt1, l.pt2);

                LDLine lp11 = new LDLine(l.pt1, this.pt1);
                LDLine lp21 = new LDLine(l.pt1, this.pt2);

                if (((this.angleTo(lp12) - 180f) * (this.angleTo(lp22) - 180f) < 0)
                    && ((this.angleTo(lp11) - 180f) * (this.angleTo(lp21) - 180f) < 0))
                {
                    point = null;
                    intersect = IntersectType.BoundedIntersection;
                }
                else
                {
                    point = null;
                    intersect = IntersectType.UnboundedIntersection;
                }
            }
            return intersect;
            */
        }
예제 #12
0
파일: LDLine.cs 프로젝트: KajitaLD/math
        /// <summary>
        /// out Upoint 未実装
        /// </summary>
        /// <param name="l"></param>
        /// <param name="point"></param>
        /// <returns></returns>
        public IntersectType intersect(LDLine l, out LDPoint point)
        {
            IntersectType intersect;
            if (MathFunctions.uFuzzyCompare(this.angle(), l.angle()))
            {
                point = null;
                intersect = IntersectType.NoIntersection;
            }
            else
            {
                LDLine lp12 = new LDLine(this.pt1, l.pt1);
                LDLine lp22 = new LDLine(this.pt1, l.pt2);

                LDLine lp11 = new LDLine(l.pt1, this.pt1);
                LDLine lp21 = new LDLine(l.pt1, this.pt2);

                if (((this.angleTo(lp12) - 180f) * (this.angleTo(lp22) - 180f) < 0)
                    && ((this.angleTo(lp11) - 180f) * (this.angleTo(lp21) - 180f) < 0))
                {
                    point = null;
                    intersect = IntersectType.BoundedIntersection;
                }
                else
                {
                    point = null;
                    intersect = IntersectType.UnboundedIntersection;
                }
            }
            return intersect;
        }