Esempio n. 1
0
        /// <summary>
        /// Move a point or list of points along a curve based on a parameter witin a range
        /// </summary>
        /// <param name="point"></param>
        /// <param name="polycurve"></param>
        /// <param name="length"></param>
        /// <param name="param"></param>
        /// <search></search>
        public static dynamic MoveAlongCurve(this DSGeom.Point point, DSGeom.PolyCurve polycurve, double length, double param)
        {
            if (length > polycurve.Length)
            {
                return("Select a segment length smaller than the length of the polycurve.");
            }
            else
            {
                double absLength = DSCore.Math.Abs(length);
                double ptParam   = polycurve.ParameterAtPoint(point);
                double dist      = polycurve.SegmentLengthAtParameter(ptParam);

                double minusDist = dist - absLength;
                double maxDist   = dist + absLength;

                if (minusDist < 0)
                {
                    minusDist = 0;
                }
                if (maxDist > polycurve.Length)
                {
                    maxDist = polycurve.Length;
                }

                Autodesk.DesignScript.Geometry.Point minusPt = polycurve.PointAtSegmentLength(minusDist);
                Autodesk.DesignScript.Geometry.Point maxPt   = polycurve.PointAtSegmentLength(maxDist);

                double number = DSCore.Math.MapTo(0, 1, param, minusDist, maxDist);
                Autodesk.DesignScript.Geometry.Point newPoint = polycurve.PointAtSegmentLength(number);
                return(newPoint);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Randomly move a point or list of points along a curve within a given percentage range.
        /// </summary>
        /// <param name="point"></param>
        /// <param name="polycurve"></param>
        /// <param name="percentage"></param>
        /// <search></search>
        public static dynamic RandomlyMoveAlongCurve(this DSGeom.Point point, DSGeom.PolyCurve polycurve, double percentage)
        {
            if (percentage > 100 || percentage < 0)
            {
                return("Select a percentage number between 0-100.");
            }
            else
            {
                double param = polycurve.ParameterAtPoint(point);
                double start = param - (percentage / 100);
                double end   = param + (percentage / 100);

                if (start < 0)
                {
                    start = 0;
                }

                if (end > 1)
                {
                    end = 1;
                }

                double        i;
                List <double> range = new List <double>();
                for (i = start; i <= end; i += 0.01)
                {
                    range.Add(i);
                }

                var random = new Random();
                int index  = random.Next(range.Count);

                double item = range[index];

                Autodesk.DesignScript.Geometry.Point newPoint = polycurve.PointAtParameter(item);
                return(newPoint);
            }
        }