Wednesday, December 13, 2006

Math is hard, let's go shopping!

Day 31

I find building jewelry in Second Life to be relaxing, rewarding and aggravating. "Relaxing" because there's a regularity to it; it's precision work, and I can just let the world fade away as I concentrate on moving little tiny prims around. It's what I imagine Zen is like, complete focus on a single thing, where time and the physical world are meaningless.

It's rewarding because there's always the challenge to slice up the prims just a teeny bit smaller than they're supposed to go, without getting them so tiny that the client won't render them anymore and they vanish, invisible and unselectable, not to be seen again until the sandbox returns your them because they've been there too long.

But it's aggravating because if you want to do things perfectly, sometimes you have to do math. And I hate math. I'm not good at it, I look at pages like this and want to run away. (And that was the least technical (and condescending!) answer in the thread!)

See, I was trying to build a better mousetrap. Necklace chains are an enormous pain to do by hand (Zen relaxation is great, but there's only so much of it I can stand). And there are a few scripts out there which will automate building necklaces, but I haven't found any which do quite what I wanted:

  1. Let the user create a cylinder and stretch it to the desired dimensions, so that the x dimension represents the width of the neck, the y dimension represents the front-to-back measurement (including the amount the chain comes forward to lie properly on the chest), and the z dimension represents the vertical curve of the chain (coming around the neck, over the shoulders and down the chest).
  2. Keep the spacing of the links constant, with no clustering or gapping if the path is elliptical.
  3. Calculate the proper number of links necessary, based on the length of the links and the distance traveled around the path.
  4. Rotate every other link 90 degrees around the axis of travel, if desired.
Doesn't sound too hard, right?

Ha! For starters, there's not even a definitive formula for finding the perimeter of an ellipse — just approximations with varying degrees of accuracy! I bashed my head against a wall for about eight hours last night and this morning, trying to get the formula in the above-linked page to work, before I finally gave up and resorted to a brute-force approach. It's not pretty, it's slow as molasses, but at least it works.

Well, what I've got written so far works — they took the grid down for updates before I was able to write the code which rotates the individual links into the proper orientation.

Once I get some decent chains made, I can put up some pictures of my jewelry!

Oh, also, a public service announcement: don't try to play Primtionary (like Pictionary, only with prims) if you've had a drink or two. The results aren't pretty.

No comments: