Пример #1
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            Rhino.Geometry.Point3d startPoint = new Rhino.Geometry.Point3d();
            DA.GetData(0, ref startPoint);

            Rhino.Geometry.Vector3d directionVector = new Rhino.Geometry.Vector3d();
            DA.GetData(1, ref directionVector);

            double lineDistance = 0;

            DA.GetData(2, ref lineDistance);

            double startingVectorLength = directionVector.Length;
            double scalingFactor        = lineDistance / startingVectorLength;

            Rhino.Geometry.Vector3d newDirectionVector = directionVector * scalingFactor;

            double deltaX = newDirectionVector.X;
            double deltaY = newDirectionVector.Y;

            double baseX = startPoint.X;
            double baseY = startPoint.Y;

            Rhino.Geometry.Point2d outputCurveEndPoint   = new Rhino.Geometry.Point2d(baseX + deltaX, baseY + deltaY);
            Rhino.Geometry.Point2d outputCurveStartPoint = new Rhino.Geometry.Point2d(baseX - deltaX, baseY - deltaY);

            Rhino.Geometry.Curve outputCurve = new Rhino.Geometry.LineCurve(outputCurveStartPoint, outputCurveEndPoint) as Rhino.Geometry.Curve;

            DA.SetData(0, outputCurve);
        }
Пример #2
0
 public static UV AsUV(Point2d value)
 {
     return(new UV(value.X, value.Y));
 }
Пример #3
0
 /// <summary>
 /// Returns a Windows Point from a Rhino.Geometry.Point2d
 /// </summary>
 /// <param name="input">Rhinocommon Point2d</param>
 /// <returns>System Windows Point</returns>
 public static Sw.Point ToWindowsPoint(this Rg.Point2d input)
 {
     return(new Sw.Point(input.X, input.Y));
 }
Пример #4
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            Rhino.Geometry.Curve rectangle = null;
            DA.GetData(0, ref rectangle);

            bool closedBool = rectangle.IsClosed;
            int  spans      = rectangle.SpanCount;
            int  degree     = rectangle.Degree;

            List <Rhino.Geometry.Point2d> originalPoints = new List <Point2d>();

            List <double> xVals = new List <double>();
            List <double> yVals = new List <double>();

            if (closedBool != true || spans != 4 || degree != 1)
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Input curve is not a closed, linear quadrilateral.");

                return;
            }

            for (int i = 0; i < spans; i++)
            {
                Rhino.Geometry.Point3d cornerPoint          = rectangle.PointAt(rectangle.SpanDomain(i).Min);
                Rhino.Geometry.Point2d flattenedCornerPoint = new Rhino.Geometry.Point2d(cornerPoint);
                originalPoints.Add(flattenedCornerPoint);

                xVals.Add(flattenedCornerPoint.X);
                yVals.Add(flattenedCornerPoint.Y);
            }

            Rhino.Geometry.LineCurve testCurveA = new Rhino.Geometry.LineCurve(originalPoints[0], originalPoints[2]);
            Rhino.Geometry.LineCurve testCurveB = new Rhino.Geometry.LineCurve(originalPoints[1], originalPoints[3]);

            if (testCurveA.GetLength() != testCurveB.GetLength())
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Input curve is not orthogonal, results are not guaranteed.");
            }

            Rhino.Geometry.Point2d topRightPoint = new Rhino.Geometry.Point2d(xVals.Max(), yVals.Max());
            DA.SetData(1, topRightPoint);

            Rhino.Geometry.Point2d topLeftPoint = new Rhino.Geometry.Point2d(xVals.Min(), yVals.Max());
            DA.SetData(2, topLeftPoint);

            Rhino.Geometry.Point2d bottomLeftPoint = new Rhino.Geometry.Point2d(xVals.Min(), yVals.Min());
            DA.SetData(3, bottomLeftPoint);

            Rhino.Geometry.Point2d bottomRightPoint = new Rhino.Geometry.Point2d(xVals.Max(), yVals.Min());
            DA.SetData(4, bottomRightPoint);

            List <Rhino.Geometry.Point2d> orderedPoints = new List <Point2d>();

            orderedPoints.Add(topRightPoint);
            orderedPoints.Add(topLeftPoint);
            orderedPoints.Add(bottomLeftPoint);
            orderedPoints.Add(bottomRightPoint);

            DA.SetDataList(0, orderedPoints);

            //TODO: Check for rotation. No warnings will be raised if input is orthogonal rotated object, but corners will not be accurate.
        }