Exemplo n.º 1
0
        /// <summary>
        /// 判断线是否位于矩形盒内(框选是否选中线)
        /// </summary>
        /// <param name="line"></param>
        /// <param name="rect"></param>
        /// <returns></returns>
        static public bool IsRectInterPolyline(PolyLine line, RectangleD rect)
        {
            //先对外包矩形判断
            if (IsMBRInterRect(line.MBR, rect) == false)
            {
                return(false);
            }
            //其他
            int sCount = line.Count;

            for (int i = 1; i < sCount; i++)
            {
                if (IsLineInterRect(line.GetPoint(i - 1), line.GetPoint(i), rect))
                {
                    return(true);
                }
            }
            return(false);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 判断点是否在Polyline上(点选是否选中线)
        /// </summary>
        /// <param name="point"></param>
        /// <param name="polyline"></param>
        /// <param name="tolerance">阈值,地理距离</param>
        /// <returns></returns>
        static public bool IsPointOnPolyline(PointD point, PolyLine polyline, double tolerance)
        {
            //先将点与外包矩形对比
            if (IsPointInRect(point, polyline.MBR) == false)
            {
                return(false);
            }
            //对每条线段求最近距离,并进行比较
            int sCount = polyline.Count;

            for (int i = 0; i < sCount - 1; i++)
            {
                double sDis = DistanceOfPointToSegment(polyline.GetPoint(i), polyline.GetPoint(i + 1), point);
                if (sDis <= tolerance)
                {
                    return(true);
                }
            }
            return(false);
        }
Exemplo n.º 3
0
    public GameObject blocksPile;             //a reference to the most recently created bundle of blocks
    public GameObject GenerateBlocks()
    {
        blocksPile = new GameObject();
        blocksPile.transform.SetParent(transform);

        //number this pile appropriately if there are already some piles on it
        int m = 0;

        for (int n = 0; n < transform.childCount; n++)
        {
            if (transform.GetChild(n).name.Contains("pile"))
            {
                m++;
            }
        }
        blocksPile.name = "pile " + (m + 1);

        //convert the spline into a polyLine
        PolyLine polyLine = spline.GetPolyLine(polyLineResolution);

        //spawn the blocks
        for (int i = 0; i < blockCount; i++)
        {
            //get the fraction along the polyline to start at
            float t = (float)i / (blockCount - 1);
            if (endPadding != 0)
            {
                t = Pad(t);
            }

            //get the position that is along the polyline
            Vector3    point = polyLine.GetPoint(t);
            Quaternion orientation;
            if (rotateToCurve)
            {
                Vector3 dir = polyLine.GetDirection(t).Flatten();
                orientation = Quaternion.LookRotation(dir, Vector3.up);
            }
            else
            {
                orientation = Quaternion.identity;
            }

            GameObject go = Instantiate(blockPrefab, point, orientation, blocksPile.transform);
            go.name = "block " + i;
        }

        return(blocksPile);
    }