Grasshopper

algorithmic modeling for Rhino

Hi,

I'm trying to speed up a boids type simulation by minimizing the number sqrt calculations involved with distances, vector lengths, and unitizing. What I'm wondering about is if the length property of a vector3d is something that is calculated only when called upon or if it's calculated up front at instantiation and just retrieved when called upon.

 

thanks,

Dave

Views: 401

Replies to This Discussion

Hi Dave,

 

it is not cached. But, are you absolutely certain that a lot of time is spend in Sqrt? It seems like a micro-optimization that's not going to help you much in the end.

 

--

David Rutten

david@mcneel.com

Delft, NL

Hi David,


Thanks for the wisdom. I had heard that sqrt stuff can slow things down with large number of agents and iterations. But then again this was from the game dev community so their idea of large is probably much bigger than mine. But if vector lengths aren't cached I'll try running distance/length checks with dist ^ 2 instead and see if it makes any difference.

Hi Dave,

minimizing sqrt can account for a sensible speed improvement in a boids-type simulation, especially if the assembly is compiled in release mode. This is still a small-scale optimization, though.

See the attached definition for a simple example.

- Giulio

_________________

giulio@mcneel.com
McNeel Europe, Barcelona

Attachments:

Thanks Giulio,


I didn't even realize that squaredlength was an existing property. Pleasant surprise.
Looks like it does a reasonable job at speeding things up though. At 500 agents it's running a little over 3x faster.

 

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service