Grasshopper

algorithmic modeling for Rhino

hi,


I am having trouble iterating a translation of points. As far as I have seen, the function Translate doesn´t work with Point3d, it only works with the class Point, which is defined by a Location which is established by the function get and there comes the whole mess!


I am attaching the code I tried (which definitely doesn´t work) in case somebody can give me a hand :-)


private void RunScript(List<Point3d> origin, List<Point3d> destination, ref object vectors, ref object points)
{
   List<Vector3d> vec = new List<Vector3d>();
   List<Rhino.Geometry.Point> pts = new List<Rhino.Geometry.Point>();

   for (int i = 0; i < origin.Count - 2; i++)
   {
     Vector3d vector = new Vector3d((destination[i].X - origin[i + 1].X), (destination[i].Y - origin[i + 1].Y), (destination[i].Z - origin[i + 1].Z));

     //Rhino.Geometry.Point punto = new Rhino.Geometry.Point(origin[i].X, origin[i].Y, origin[i].Z); // this doesn´t work, has to be defined by a location

    //Location localizacion = new Location(origin[i]);
    //Rhino.Geometry.Point punto = new Rhino.Geometry.Point(localizacion); //wrong again!

    if(origin[i + 1].Translate(vector)) //Point3d doesn´t work with Translate
    {
      pts.Add(origin[i + 1]); 
    }
    vec.Add(vector);
    }

   points = pts;
   vectors = vec;
}


Thanks in advance


Cheers!

Views: 4874

Replies to This Discussion

Hi Miguel,

I do not exactly know what this does, but this code expresses the idea you give in the text.

List<Vector3d> vec = new List<Vector3d>();
List<Point3d> pts = new List<Point3d>();

for (int i = 0; i < origin.Count - 1; i++)
{
Vector3d vector = destination[i] - origin[i + 1];
pts.Add(origin[i + 1] + vector);
vec.Add(vector);
}

points = pts;
vectors = vec;


I hope this helps.

- Giulio
________________________
giulio@mcneel.com
McNeel Europe, Barcelona
Attachments:
Hi Giulio,

Thanks for your response. Actually I think I didn´t explain correctly, the question was:

- how to use the function translate with points
- how to define a Rhino.Geometry.Point with "location"
Hi Miguel,

- how to use the function translate with points
The Point3d structure does not have a Translate method. Here is the list of all methods of Point3d
You can add a Vector3d to a Point3d and two Point3ds using the + operator.
Or you can call the Transform method with a Matrix.
On the other hand, the class Point has a translate method that it inherits from GeometryBase. You can read about it below.

- how to define a Rhino.Geometry.Point with "location"
You probably do not need to do this. Point is a class that wraps the tiny Point3d structure. But if in any case you want to construct a Point class, you will need to use its constructor. Example:
A = new Rhino.Geometry.Point(new Point3d(5,6,7));
You can modify the location assigning the Location property:
Rhino.Geometry.Point p;
p = new Rhino.Geometry.Point(new Point3d(5,6,7));
// later...
p.Location = new Point3d(12, 12, 12);
// or, alternatively, as Point has a translate method
p.Translate(new Vector3d(7, 6, 5));

I hope this helps,

- Giulio
________________________
giulio@mcneel.com
McNeel Europe, Barcelona
Thanks, Giulio. Sure it helped! I didn´t know how "location" worked

Cheers

RSS

About

Translate

Search

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service