コード例 #1
0
ファイル: AnchorsMgr.cs プロジェクト: zhudaijie/SharpCAD
        internal LitMath.Vector2 Snap(LitMath.Vector2 posInCanvas)
        {
            LitMath.Vector2 posInModel = _presenter.CanvasToModel(posInCanvas);

            foreach (KeyValuePair <ObjectId, List <GripPoint> > kvp in _gripPnts)
            {
                int index = -1;
                foreach (GripPoint gripPnt in kvp.Value)
                {
                    ++index;
                    double          width           = 10;
                    double          height          = 10;
                    LitMath.Vector2 gripPosInCanvas = _presenter.ModelToCanvas(gripPnt.position);
                    gripPosInCanvas.x -= width / 2;
                    gripPosInCanvas.y -= height / 2;
                    LitMath.Rectangle2 rect = new LitMath.Rectangle2(gripPosInCanvas, width, height);

                    if (MathUtils.IsPointInRectangle(posInCanvas, rect))
                    {
                        _currGripPoint      = gripPnt;
                        _currGripEntityId   = kvp.Key;
                        _currGripPointIndex = index;
                        return(gripPnt.position);
                    }
                }
            }

            _currGripPoint      = null;
            _currGripEntityId   = ObjectId.Null;
            _currGripPointIndex = -1;
            return(posInModel);
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: xmzhan/LitMath
        static void Main(string[] args)
        {
            //LitMath.Vector2 v = new LitMath.Vector2(0.7, 0.7);
            //v = LitMath.Vector2.RotateInRadian(v, LitMath.Utils.PI / 2);
            //Console.WriteLine(v.ToString());
            //Console.WriteLine(Math.Asin(0.5).ToString());

            {
                LitMath.Vector3 va    = new LitMath.Vector3(0, 0, 1);
                LitMath.Vector3 vb    = new LitMath.Vector3(0, 1, 0);
                LitMath.Vector3 axis  = new LitMath.Vector3(1, 1, 0);
                double          angle = LitMath.Vector3.SignedAngle(va, vb, axis);
                Console.WriteLine(angle);
            }
            {
                LitMath.Vector3 va    = new LitMath.Vector3(0, 0, 1);
                LitMath.Vector3 vb    = new LitMath.Vector3(0, 0, 1);
                LitMath.Vector3 axis  = new LitMath.Vector3(1, 1, 0);
                double          angle = LitMath.Vector3.SignedAngle(va, vb, axis);
                Console.WriteLine(angle);
            }
            {
                LitMath.Vector3 va    = new LitMath.Vector3(0, 0, 1);
                LitMath.Vector3 vb    = new LitMath.Vector3(0, 1, 0);
                LitMath.Vector3 axis  = new LitMath.Vector3(0, 1, 1);
                double          angle = LitMath.Vector3.SignedAngle(va, vb, axis);
                Console.WriteLine(angle);
            }


            return;

            //LitMath.Vector2 v1 = new LitMath.Vector2(1, 3);
            //Console.WriteLine(v1.ToString());

            LitMath.Line2 line1 = new LitMath.Line2(
                new LitMath.Vector2(0, 0),
                new LitMath.Vector2(10, 0));
            line1.startPoint.x = 10;
            LitMath.Line2 line2 = new LitMath.Line2(
                new LitMath.Vector2(5, 0),
                new LitMath.Vector2(5, 10));

            LitMath.Vector2 intersection = new LitMath.Vector2();
            if (LitMath.Line2.Intersect(line1, line2, ref intersection))
            {
                Console.WriteLine("相交: " + intersection.ToString());
            }

            LitMath.Rectangle2 rect = new LitMath.Rectangle2(new LitMath.Vector2(10, 10), 10, 20);
            Console.WriteLine(rect.ToString());
            Console.WriteLine(rect.leftBottom.ToString());
            Console.WriteLine(rect.leftTop.ToString());
            Console.WriteLine(rect.rightTop.ToString());
            Console.WriteLine(rect.rightBottom.ToString());

            LitMath.Circle2 circle = new LitMath.Circle2(new LitMath.Vector2(25, 25), 10);
            Console.WriteLine(circle.ToString());
            Console.WriteLine(circle.diameter.ToString());
        }
コード例 #3
0
ファイル: MathUtils.cs プロジェクト: zy850580380/LitCAD
        /// <summary>
        /// 点是否在矩形内
        /// </summary>
        internal static bool IsPointInRectangle(LitMath.Vector2 point, LitMath.Rectangle2 rect)
        {
            LitMath.Vector2 rectLeftBottom = rect.leftBottom;
            LitMath.Vector2 rectRightTop   = rect.rightTop;

            if (point.x >= rectLeftBottom.x &&
                point.x <= rectRightTop.x &&
                point.y >= rectLeftBottom.y &&
                point.y <= rectRightTop.y)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
コード例 #4
0
        internal override bool Cross(Bounding selectBound, Entity entity)
        {
            Polyline polyline = entity as Polyline;

            if (polyline == null)
            {
                return(false);
            }

            Bounding polylineBound = polyline.bounding;

            if (selectBound.Contains(polylineBound))
            {
                return(true);
            }

            LitMath.Rectangle2 selRect = new LitMath.Rectangle2(
                new LitMath.Vector2(selectBound.left, selectBound.bottom),
                new LitMath.Vector2(selectBound.right, selectBound.top));

            LitMath.Line2 rectLine1 = new LitMath.Line2(selRect.leftBottom, selRect.leftTop);
            LitMath.Line2 rectLine2 = new LitMath.Line2(selRect.leftTop, selRect.rightTop);
            LitMath.Line2 rectLine3 = new LitMath.Line2(selRect.rightTop, selRect.rightBottom);
            LitMath.Line2 rectLine4 = new LitMath.Line2(selRect.rightBottom, selRect.leftBottom);

            for (int i = 1; i < polyline.NumberOfVertices; ++i)
            {
                LitMath.Vector2 spnt         = polyline.GetPointAt(i - 1);
                LitMath.Vector2 epnt         = polyline.GetPointAt(i);
                LitMath.Line2   line2        = new LitMath.Line2(spnt, epnt);
                LitMath.Vector2 intersection = new LitMath.Vector2();
                if (LitMath.Line2.Intersect(rectLine1, line2, ref intersection) ||
                    LitMath.Line2.Intersect(rectLine2, line2, ref intersection) ||
                    LitMath.Line2.Intersect(rectLine3, line2, ref intersection) ||
                    LitMath.Line2.Intersect(rectLine4, line2, ref intersection))
                {
                    return(true);
                }
            }

            return(false);
        }
コード例 #5
0
ファイル: LineRS.cs プロジェクト: zhudaijie/SharpCAD
        internal override bool Cross(Bounding selectBound, Entity entity)
        {
            Line line = entity as Line;

            if (line == null)
            {
                return(false);
            }

            Bounding lineBound = line.bounding;

            if (selectBound.Contains(lineBound))
            {
                return(true);
            }

            LitMath.Rectangle2 selRect = new LitMath.Rectangle2(
                new LitMath.Vector2(selectBound.left, selectBound.bottom),
                new LitMath.Vector2(selectBound.right, selectBound.top));

            LitMath.Line2 rectLine1 = new LitMath.Line2(selRect.leftBottom, selRect.leftTop);
            LitMath.Line2 rectLine2 = new LitMath.Line2(selRect.leftTop, selRect.rightTop);
            LitMath.Line2 rectLine3 = new LitMath.Line2(selRect.rightTop, selRect.rightBottom);
            LitMath.Line2 rectLine4 = new LitMath.Line2(selRect.rightBottom, selRect.leftBottom);
            LitMath.Line2 line2     = new LitMath.Line2(line.startPoint, line.endPoint);

            LitMath.Vector2 intersection = new LitMath.Vector2();
            if (LitMath.Line2.Intersect(rectLine1, line2, ref intersection) ||
                LitMath.Line2.Intersect(rectLine2, line2, ref intersection) ||
                LitMath.Line2.Intersect(rectLine3, line2, ref intersection) ||
                LitMath.Line2.Intersect(rectLine4, line2, ref intersection))
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }