Is there a good formula to convert polar coordinates to cartesian?
In some DMs, I want to be able to move the effect around. I tried searching the web, but found no good answers.
polar to cartesian?
14 posts
x=cos(r)*d;y=sin(r)*d;
r=atan2(y,x);
d=sqrt(sqr(x)+sqr(y));
Though in AVS, the zero angle axis is oriented differently..
r=atan2(y,x);
d=sqrt(sqr(x)+sqr(y));
Though in AVS, the zero angle axis is oriented differently..
In AVS:
r=atan2(x,-y);
d=sqrt(x*x+y*y)/sqrt(2); (if that doesn't work right then switch /sqrt(2) to *sqrt(2))
r=atan2(x,-y);
d=sqrt(x*x+y*y)/sqrt(2); (if that doesn't work right then switch /sqrt(2) to *sqrt(2))
Btw atero, sqr(x) is faster than x*x I believe.
uhh...no, you of all people should know that calling upon a function is faster than using basic operators
Here's the deal... AVS is NOT a typical programming language. It's a high-level scripting language, which means it's miles and miles away from the instructions that the CPU receives. Obviously you haven't heard of a little thing called inline operators.
First of all, having to type a*b or multiply(a,b) is just a difference in syntax. So just because an operation is defined using a function-like syntax doesn't mean that the code for that operation is stored in one place in memory that is jumped to and from every time it's needed. Just like the multiply and addition operator, the square operator's code is repeated every time it's needed, because the increase in memory is less important than the slowdown you'd get from having to jump around the code (effectively destroying the instruction cache every time the operator is needed).
Secondly, AVS has little or no optimizations. So, using 'a*a' will most like cause it to load the variable 'a' twice. By using sqr(), you explicitly indicate that you want to square the variable, which means it knows it has to perform a multiplication with the same variable on both sides, which means it only has to fetch it from memory once.
This goes for most AVS 'functions' actually. The sine function is a built-in cpu instruction, so it's very likely that if I do sin(a), then the compiled code would simply put a sine instruction right after loading the variable 'a', and not call a separate function in memory for that.
First of all, having to type a*b or multiply(a,b) is just a difference in syntax. So just because an operation is defined using a function-like syntax doesn't mean that the code for that operation is stored in one place in memory that is jumped to and from every time it's needed. Just like the multiply and addition operator, the square operator's code is repeated every time it's needed, because the increase in memory is less important than the slowdown you'd get from having to jump around the code (effectively destroying the instruction cache every time the operator is needed).
Secondly, AVS has little or no optimizations. So, using 'a*a' will most like cause it to load the variable 'a' twice. By using sqr(), you explicitly indicate that you want to square the variable, which means it knows it has to perform a multiplication with the same variable on both sides, which means it only has to fetch it from memory once.
This goes for most AVS 'functions' actually. The sine function is a built-in cpu instruction, so it's very likely that if I do sin(a), then the compiled code would simply put a sine instruction right after loading the variable 'a', and not call a separate function in memory for that.
Speaking of which, which is faster, integer divide or floating-point multiply?
I think Atero treats all constants to floating point (considering the integer instructions are explicitly marked as so in the help), so a multiply would be faster.
Little Freudian slip there, UnsToneD? 😛
Not really, that's more like 4am affecting my typing skills while chatting with you. I was completely clear of any influencing substances at the time 😛. In fact I haven't smoked for 2 weeks because exams are nearing and I've got a lot to do.
Originally posted by AteroAn operator is a function. If they both do the exact same thing then neither should be faster than the other.
uhh...no, you of all people should know that calling upon a function is faster than using basic operators
Schouldnt lower level functions be faster than higher level ones.
+ - are faster than * / which are faster than ^ so a*a is faster than using sqr(a).
+ - are faster than * / which are faster than ^ so a*a is faster than using sqr(a).
nixa: what I wanted to explain is that AVS is so far from the code that the CPU receives, that you can't talk about how things work by guessing.
If sqr() was slower than multiply, would they have left it in? No... by using sqr(), you tell AVS you want to square a number. By using a*a, you're telling AVS you want to multiply two numbers (which just happen to be identical, but AVS doesn't notice that).
If it loads the var twice, the cpu has to wait longer and so it slows the calculation.
If sqr() was slower than multiply, would they have left it in? No... by using sqr(), you tell AVS you want to square a number. By using a*a, you're telling AVS you want to multiply two numbers (which just happen to be identical, but AVS doesn't notice that).
If it loads the var twice, the cpu has to wait longer and so it slows the calculation.