Grasshopper

algorithmic modeling for Rhino

Dear Reader,

I want to Rotate my shapes to fix by some angles.

I have get the Surface like this :

Surface sr = obj_ref.Surface();

then for example i want to rotate it like this:

Point3d P = new Point3d(0, 0, 0);
Vector3d D = new Vector3d(10, 10, 10);

sr.Rotate(30,D,P);

doc.Objects.AddSurface(sr);

doc.Views.Redraw();

but noting happened in rotation and the Surface just duplicate.

Can you help me to rotate my shape ?

Views: 1968

Replies to This Discussion

Hi Mohammad,
sr.Rotate(Math.Pi/6, D, P) returns a boolean. If it's a True value, then the rotation was succesfull and you can asign the rotated geometry. (30 radians seems to be wrong in your script)

Dear Pieter,

Thanks for your help, I have changed the Rotate syntax to this :

bool RES = sr.Rotate((Math.PI / 6), D, P);

but still I get RES=false 

how can I find what is the problem ?

In VB I do this:

If sr.Rotate(Math.Pi/6, D, P) Then
rotatedgeo = sr
End If

This is my code in C#. RES == TRUE but still the shape don't rotated :((

Point3d P = new Point3d(0, 10, 20);
Point3d Prev_Point = P;
Vector3d D = new Vector3d(2.0, 0, 0);


bool RES = obj_ref.Geometry().Rotate((Math.PI / 6), D, P);

Surface sr = obj_ref.Surface();

doc.Objects.AddSurface(obj_ref.Surface());

doc.Views.Redraw();

Please HELP :(( :((

See attached.

Attachments:

It solved.

I just change my obj_ref type, The final working code is this :

Point3d P = new Point3d(0, 0, 0);
Vector3d tetta_D = new Vector3d(0, 1, 0);
Vector3d phi_D = new Vector3d(1, 0, 0);
Brep br;
Point3d center;

br = obj_ref.Brep();
center = br.GetBoundingBox(true).Center;

RES = br.Translate(-center.X, -center.Y, -center.Z);
RES = br.Rotate(-tetta_radian, tetta_D, P);
RES = br.Rotate(-phi_radian, phi_D, P);

doc.Objects.Replace(obj_ref.ObjectId, br);
doc.Views.Redraw();

This Code move object to center and rotate it by tetta and phi inradian .

It solved.

I just change my obj_ref type, The final working code is this :

Point3d P = new Point3d(0, 0, 0);
Vector3d tetta_D = new Vector3d(0, 1, 0);
Vector3d phi_D = new Vector3d(1, 0, 0);
Brep br;
Point3d center;

br = obj_ref.Brep();
center = br.GetBoundingBox(true).Center;

RES = br.Translate(-center.X, -center.Y, -center.Z);
RES = br.Rotate(-tetta_radian, tetta_D, P);
RES = br.Rotate(-phi_radian, phi_D, P);

doc.Objects.Replace(obj_ref.ObjectId, br);
doc.Views.Redraw();

This Code move object to center and rotate it by tetta and phi inradian .

RSS

About

Translate

Search

Photos

  • Add Photos
  • View All

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service