PDA

View Full Version : cartesian to polar conversion using nodes...



AbstractTech3D
02-17-2012, 03:29 AM
Hello

Am trying to convert cartesian to polar coordinates, so as to produce a radial gradient - not concentric but varying by angle.

Have tried producing a complex logical nodal setup based on cartesian to polar logic found on this page:
http://en.wikipedia.org/wiki/Polar_coordinate_system#Converting_between_polar_a nd_Cartesian_coordinates

…but have not yielded working results.

Is there an easier way?
Is there a node somewhere for converting cartesian to polar?

(It would seem an obvious procedure for plugin developers / NT to include, I would have thought!)


Thanks

RebelHill
02-17-2012, 04:46 AM
this is where I start to probe a bit beyond my ability to do the math, or understand computer programming... but Im gonna take a lil stab anyway. I think LightWolf, or DP, or similar are gonna be the guys to give u a proper answer, and Id sure be interested to hear how close to the mark I come...

I think your main problem building this nodally comes from the atan2 function... which we dont have a node or similar for. So there's your dead end. Now atan2 does have a definition (exists as a tool) in different programming languages, including C (which is what LWs plugins are (or can) be written in, so there's probably an atan2 available somewhere via the sdk... I would hazard.

If so, then you should be able to take template plugin code for a (basically empty) node plugin, and just stick the atan2 function inside it (as a doubtless massive oversimplification).

Load the plugin, and boom... there's your atan2.

Ofc, even if this is correct, and u did it, it may not help in the end.

Ive tried before to make an IK solver nodally... pretty simple really, its very basic 2D trig. The problem comes from the fact that there's no way to start dictating behaviours in the node tree of what needs to happen at certain conditions (save basic clamps, hold value above/below)... so the result is an IK chain that works fine until it reaches a certain level of extension or bend, at which point it goes spaz... cos the values being returned have been reduced to junk, and the only thing I could do (or at least find to do) was clamp it.... basically, restrict its movement. Not much use.

My point is... even if you had all the math and value nodes needed to build the "solve", LWs node system may not have the... expressional versatility (for my own want of a better term) to produce what you're after without errors somewhere, and so the only way to get the function you're after could be to fully code it, as a plugin, giving you in LW, a single, self contained, "cart2polar" node.

Sensei
02-17-2012, 06:06 AM
in such system you have length and angle

length = sqrt(x*x+y*y+z*z)
so you can just use Math > Vector > Distance node, using Spot Info as argument. Or if you want it to work just 2D multiply it by 1,0,1 or similar to get ride off one axis.

ArcTan node is in Math > Trigonometry > ArcTan..

http://forums.newtek.com/attachment.php?attachmentid=101847&stc=1&d=1329485236

AbstractTech3D
02-17-2012, 07:12 AM
Beautiful.

I don't understand how it works (completely), but it works!