Wow, it’s been a ridiculously long time since I posted to my own blog *Insert Titanic lady GIF here*. It’s a great thing I forgot how to do a thing and I decided to write it down for me to be able to find it 3 years later when I need it again.
For a show I worked on with a bunch of stadium crowds, I developed a little VEX snippet to identify a slice of the stadium to trigger a change in the agent state (for a wave, typical stadium stuff).
Yesterday I needed this and I had entirely forgotten the math and how I wrote the code. I knew I needed to convert from cartesian to polar, though. And I had a general idea of how it should work in my mind. With no access to the project files anymore and armed with my vague hints, I started the hunt for answers. Some of you might think “Wow, I cannot believe this guy doesn’t know this”, to which I say in my defense: “I know, it’s shameful”.
In any case, I won’t bore you with details, but after some searches online, and a conversation with someone/something that may or may not be an LLM AI, I put together my VEX snippet (and if I remember correctly, this one is actually better than the previous one, because of the modulo on the angle
variable. This allows for continuous rotation!).
Here is the code:
//This attribute will be used to tag the section of interest
@polar_tag = 0;
//Control parameters
float slice = radians(chf("slice"));
float offset = radians(chf("offset"));
//Just in case the geometry I'm playing with is not at the center of the world
vector centroid = getbbox_center(0);
vector pos = centroid-@P;
//Cartesian to polar
float angle = atan2(pos.x, pos.z);
//add offset
angle += offset;
//make it repeatable, yay!
angle = angle%radians(360);
// Normalize angle to be within 0 and 2*$PI
if(angle<0){
angle += 2 *$PI;
}
//tag the outcome
if(angle
There is always room for improvement, so if you see anything that could be better, please do let me know!