Points in Rhino viewport from Grasshopper

Get a point between two points in Grasshopper with C#

How to get a point a certain ratio between two points in Grasshopper, using the C# component.

The method below allows you to return a point between two input points. Input two Point3d values and a number between 0 and 1.

‘Ratio’ is a value between 0 and 1. Enter 0 and the resultant point will be on top of frompt. Enter 1 and it will be on top of the topt. Enter something between, and the point will also be between. You can also enter a value that is !=[0,1] to extrapolate.

The easiest way to use the method is to paste it into the ‘additional code’ section of the C# component.

C# method

  private void RunScript(Point3d pt1, Point3d pt2, double t, ref object A)
  {

    A = MovePoint(pt1, pt2, t);

  }

  // <Custom additional code> 
  public Point3d MovePoint(Point3d frompt, Point3d topt, double ratio)
  {
    return new Point3d(ratio * (topt.X - frompt.X) + frompt.X, 
      ratio * (topt.Y - frompt.Y) + frompt.Y, 
      ratio * (topt.Z - frompt.Z) + frompt.Z);
  }
  // </Custom additional code> 

Grasshopper C# component points ratio

Points in Rhino viewport from Grasshopper

Leave a Reply

Your email address will not be published.

Time limit is exhausted. Please reload CAPTCHA.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: