Grasshopper

algorithmic modeling for Rhino

Goodevening to everyone,

i am going to ask you all a very basic question but i am starting to code with python these days.

i should need to scale an object (uniform scale) till it reach a set volume value to stop, reading wich scaling factor has been used.

following what i've done so far:

mesh = x

center = rs.MeshVolumeCentroid(x)

scaling_factor = 0

target_volume = 400

while scaling_factor < 10000:

         LOOP = rs.scaleObject(x,center,scaling_factor)

         if rs.MeshVolume(LOOP) == target_volume:

                  break

         a = LOOP

Hope you can help me. I am trying to translate a grasshopper definition made with ANEMONE into python.

Thank you very much in advance

Nick

Views: 1069

Replies to This Discussion

Unfortunately, that looks too far gone to be saved... :S

The volume will never (or extremely rarely) be exactly 400, so you have to check when it goes over (>= instead of ==). Then just output the scaling_factor and the temp object as well if you wish.

You also have to choose how your scaling factor will grow... Will it grow linearly? Or exponentially?

center = rs.MeshVolumeCentroid(x)

scaling_factor = 1.0

target_volume = 400.0

temp = x

while scaling_factor < 10000.0:

    temp = rs.scaleObject(temp, center, scaling_factor)

    if rs.MeshVolume(temp) >= target_volume:

        break

    scaling_factor = scaling_factor * 1.1

a = scaling_factor

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