Grasshopper

algorithmic modeling for Rhino

Hi everyone, 

I've recently been trying to learn python in order to automate some external functions from within grasshopper. As an exercise, I've been trying to translate a serpinski triangle script from C# to Python, but as they are two different languages, I've gotten stuck on a specific function.

I can already make a point within python by using Rhino.Geometry.Point3d(x, y, z), but I can't figure out how to use Rhino.Geometry.Transform.Rotation.

The below function takes an input of two Point3d objects (points a and b, in this case).

Two points are then found between the points-- 1/3 between the two and 2/3 between the two points (p1 and p2, respectively). What I am trying to do is rotate p2 about p1. I'm not sure where to introduce p2 into the function I made in order to do this.

--------------

def PtB(a, b):
      p1 = a + ((b - a) / 3)
      p2 = a + (2 * (b - a) / 3)

      Rhino.Geometry.Transform.Rotation(-math.pi / 3, Rhino.Geometry.Vector3d.ZAxis, p1)

--------------

The way this is done in the C# script I am referencing is the following:

Transform trans = Transform.Rotation(-Math.PI / 3, Vector3d.ZAxis, p1)

p2.Transform(trans)

Does anyone have any tips? 

Also, I've been working in grasshopper 1.0.0004 in Rhino 6 WIP since Rhino 5 crashes when I try to open the python script editor within the older version of grasshopper.

Views: 2731

Attachments:

Replies to This Discussion

Hi Marcus,

Thanks for the help. Unfortunately, I keep getting null results from using the method in the script you linked. Everything seems to go well until I have to actually apply the transformation (see screenshot and script below):

Thanks again for your help

Attachments:
Hmm, I removed the "p3 =", but I am still getting a null result. I finally reinstalled rhino and fixed ghpython and it doesn't work in the current stable release either, so I must be doing something wrong, but I can't figure out what it is

Hi Christian

You need to see rhinocommon SDK Point3d.Transform(),This method does not return value.Function needs to return a value

Does this help?

___Naruto

Hi Christian

You need to see rhinocommon SDK Point3d.Transform(),This method does not return value.Function needs to return a value

Does this help?

___Naruto

Yes! That fixed the problem. Thanks again for the help.

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