Example #1
0
            //与えられた点群すべてを含む矩形を取得
            public static LDRect getBoundingRect(LDPointList form)
            {
                float maxX = float.MinValue;
                float minX = float.MaxValue;
                float maxY = float.MinValue;
                float minY = float.MaxValue;
                foreach (var p in form)
                {
                    float x = p.x();
                    float y = p.y();
                    if (x < minX)
                    {
                        minX = x;    //  最小のx
                    }
                    if (x > maxX)
                    {
                        maxX = x;    //  最大のx
                    }
                    if (y < minY)
                    {
                        minY = y;    //  最小のy
                    }
                    if (y > maxY)
                    {
                        maxY = y;    //  最大のy
                    }
                }

                LDRect rect = new LDRect();
                rect.setLeft(minX);
                rect.setRight(maxX);
                rect.setTop(minY);
                rect.setBottom(maxY);
                return rect;
            }
Example #2
0
 public void setRect(LDRect r)
 {
     x      = r.x;
     y      = r.y;
     width  = r.width;
     height = r.height;
 }
Example #3
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 #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 LDRect getBoundingRect(LDPointList form)
            {
                float maxX = float.MinValue;
                float minX = float.MaxValue;
                float maxY = float.MinValue;
                float minY = float.MaxValue;

                foreach (var p in form)
                {
                    float x = p.x();
                    float y = p.y();
                    if (x < minX)
                    {
                        minX = x;    //  最小のx
                    }
                    if (x > maxX)
                    {
                        maxX = x;    //  最大のx
                    }
                    if (y < minY)
                    {
                        minY = y;    //  最小のy
                    }
                    if (y > maxY)
                    {
                        maxY = y;    //  最大のy
                    }
                }

                LDRect rect = new LDRect();

                rect.setLeft(minX);
                rect.setRight(maxX);
                rect.setTop(minY);
                rect.setBottom(maxY);
                return(rect);
            }