Grasshopper

algorithmic modeling for Rhino

Help with math, feedback on amateur Python code, general show and tell for crit

Hi folks,

I am working on a python script that is basically doing an attractor point operation on an arbitrary number of input points with an arbitrary number of attractors. The objective is to have each attractor exert a weighted influence over all the field points in its range, such that the final position of each point is determined by the sum of the influences.

The good news is, my script is working! I resisted coming here with all my little problems.

Help I would love to get:

First, I am pretty new with Python and it would be awesome if one or two would give me some pointers if anything jumps off the page at you like "Oh, dear, that is a stupid way to do that," or, "wow, somebody needs to teach this guy some conventions." (Lookin' at you, Anders).

Second, you may notice that there is a gene pool which does nothing called 'half_saturation_distances'. Currently the falloff in weight is linear. I would really like to be able to adjust this to be closer or further, with the resulting falloff curve being smooth and continuous, not kinked in the middle. So what I need is a function that has a kind of a S-curve shape and is relatively easy to implement. If anyone has any suggestion, that would be great!

As you may imagine, this project is an early attempt at creating a tool that will allow editing terrain in the form of point elevations. I hope to continue to build it out until it's actually useful!

Views: 507

Attachments:

Replies to This Discussion

To me personally, as more of a geometer than a programmer, the object oriented format forced onto such a simple little program means I can't follow what it's doing. I don't understand the global variable use either, since you're re-declaring variables already assigned to empty lists. So, as a chemist by training, I instinctively "distill" such code down so I can follow it in linear fashion.

For instance, to understand:

#Calculate vector influences by distance, weight, range, falloff----
for a in active_attractors:
  for p in living_points:
    a.field(p)

...I have to keep looking up at the class definition, far above, and active_attractors is itself knotted into some function inside a function sort of thing with "influence" being used from yet another class.

From my background, the object oriented structure merely obfuscates in the extreme what is happening. Instead of judging what the code is doing I'm having to parse which part of a class is being called and what you've re-named a perfectly good existing variable to inside of it.

Given how few Python programmers are using Grasshopper, using classes and even unneeded functions instead of inline code means it's harder for C# and VB users to help out with questions.

Finally, though object oriented format is the mantra for code re-use, since it's tied in knots instead of linear, I cannot personally re-use your code at all and certainly this is also the case with everyday architects who enjoy normal Grasshopper and might want to tweak a Python script or use part of it.

Thanks Nik! I really appreciate your candid reply.

The reasons I went with an OO format are 2: this may be simple now, but I have big ambitions for functionality to add as I muddle through familiarizing myself with writing decent Python; I am playing with a conceptual metaphor of terrain as 'field' and spot elevations as bodies which are responsive to 'messenger particles' (if you will) from multiple generators.

And to be honest, I'm not sure how I would build it linearly, since I've really struggled to implement this concept using GH components. 

You critique about naming variables is on point, that's something I really don't understand the idiom well for, and the whole name space business is kind of over my head still. Would be great to hear suggestions about how to improve understanding that stuff.

Thanks again!

Well, this doesn't do quite the same thing, but that's because I don't understand your script well. It results in the same type of field influence though, in only a few lines. After all there's really just a loop in a loop adding up influence of all the attractors on each point.

Original:

Point well taken :)

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