Converting Polar from Cartesian not working??

Discussion forum for G-Force users

Moderators: BTT, andy55, b.dwall, juxtiphi

Post Reply
Rovastar
Posts: 295
Joined: Wed May 05, 2004 9:25 am
Location: Derby/London, England

Converting Polar from Cartesian not working??

Post by Rovastar »

Andy/JayPro/Anybody

Can you explain how teh theta value is calculated in GForce I don't get it


I was trying to do some more intersting config from teh basic one I have done already for thsi one of the things I was after was 'creating me own' theta and radial values and changing them.

So I did the simple Polar from Cartesian conversions for this.

e.g.

R=Sqrt((x*x)+(y*y));
Theta=ArcTan(Y/X);

now I don't get the same on screen display for the theta values. How is the ArcTan function working.


D0 = "x", //newx
D1 = "y", //newy
D2 = "sqrt(D0*D0 +D1*D1)", //newrad
D3 = "atan(D1/D0)", //newtheta

srcX = "x - 0.0025*D3",
srcY = "y - 0.0025*D3",

is different

srcX = "x - 0.0025*theta",
srcY = "y - 0.0025*theta",

Now I am expecting them to be the same. Have a made a mistake? Can someone enlighten me?

(later I will use D0- A0 (where a0 = 0.1*(rnd(10)-5)) to create interesting scenes you will see.:) )
Last edited by Rovastar on Wed Jul 14, 2004 9:16 am, edited 1 time in total.

Rovastar
Posts: 295
Joined: Wed May 05, 2004 9:25 am
Location: Derby/London, England

Post by Rovastar »

Hold on I am getting lost now.

Maybe I am wrong but is

D0 = "x", //newx
D1 = "y", //newy
D2 = "sqrt(D0*D0 +D1*D1)", //newrad
D3 = "atan(D1/D0)", //newtheta

using the correct interputation of theta -180 to 180 or 0 to 360 with that sudden cut of point. e.g.
x = +'ve and y = just +'ve theta = just above 0
x = +'ve and y = 0 theta = 0
x = +'ve and y = just -'ve theta = just below 360

you are using some sort of strange rounded unsigned version to make it smooth. e.g if theta > 360 then theta =0 or something.

I try and do that the limited code based of Gforce....ummmh

....I really don't get this at all..... :? :? :?

Rovastar
Posts: 295
Joined: Wed May 05, 2004 9:25 am
Location: Derby/London, England

Post by Rovastar »

*bump*

Rovastar
Posts: 295
Joined: Wed May 05, 2004 9:25 am
Location: Derby/London, England

Post by Rovastar »

*bump* can anyone help me?

User avatar
andy55
Site Admin
Posts: 569
Joined: Sat May 01, 2004 4:38 pm
Contact:

Re: Converting Polar from Cartesian not working??

Post by andy55 »

Rovastar wrote:Andy/JayPro/Anybody

Can you explain how teh theta value is calculated in GForce I don't get it


I was trying to do some more intersting config from teh basic one I have done already for thsi one of the things I was after was 'creating me own' theta and radial values and changing them.

So I did the simple Polar from Cartesian conversions for this.

e.g.

R=Sqrt((x*x)+(y*y));
Theta=ArcTan(Y/X);

now I don't get the same on screen display for the theta values. How is the ArcTan function working.


D0 = "x", //newx
D1 = "y", //newy
D2 = "sqrt(D0*D0 +D1*D1)", //newrad
D3 = "atan(D1/D0)", //newtheta

srcX = "x - 0.0025*D3",
srcY = "y - 0.0025*D3",

is different

srcX = "x - 0.0025*theta",
srcY = "y - 0.0025*theta",

Now I am expecting them to be the same. Have a made a mistake? Can someone enlighten me?

(later I will use D0- A0 (where a0 = 0.1*(rnd(10)-5)) to create interesting scenes you will see.:) )
Here's what's happening...

theta goes from -pi to pi (where 0 is the ray (0,0)(inf,0). If you make a flowfield using the theta config you used, you'll see this (ie, you'll see contuniuty of flow everywhere except through the ray (0,0)(-inf,0).

atan() returns -pi/2 to pi/2, making its boundry of discontinuity the entire y axis.

After reading this post, I've added a new fucntion to G-Force 2.6.8, atan2(), which will go from 0 to pi. (Until it is released, you can emulate it with atan(D2)+PI*pos(-D2) ).

Perhaps I can help you convert a specific FlowField given the atan() range. In any case, thanks for this post--it's also caused me to add a little to the docs (so somone in the future w/ this issue will have it answered).

Andy

Rovastar
Posts: 295
Joined: Wed May 05, 2004 9:25 am
Location: Derby/London, England

Post by Rovastar »

Hi Andy thanks for the reply.

I sort of know what was happening but it was difficult to expalin without without understanding how you did the code.

I still though cannnot get the hang of the example of:

atan(D2)+PI*pos(-D2)

D0 = "x", //newx
D1 = "y", //newy
D2 = "sqrt(D0*D0 +D1*D1)", //newrad
D3 = "atan(D1/D0)",

It presume you didn't mean D2 as in "sqrt(D0*D0 +D1*D1)" but I try

atan(y/x)+PI*pos(-y/x)

and others but could not get it to emulate correctly theta. No matter atan2 is what I am really after anyway. I am used to that as a function.

Just simply in the example

Srcx = "x",
SrcY = "y - 0.00025*theta",

and

Srcx = "x",
SrcY = "y - 0.00025*D3",

User avatar
andy55
Site Admin
Posts: 569
Joined: Sat May 01, 2004 4:38 pm
Contact:

Post by andy55 »

Rovastar wrote: but I try

atan(y/x)+PI*pos(-y/x)

and others but could not get it to emulate correctly theta.

The atan2() equivilent I gave returns from 0 to pi. atan() and atan2() will never (and cannot) have a range span greater than pi because i would otherwise need to have two signs (ie, it needs to know the sign of x and the sign of y). Basically, I'm saying that atan() willl only look like theta from 0 to pi (and will b discontinuous in that something like -1/-.001 will return the same as 1/.001--the first on is in quadrant III and the second one is in quadrant I).

andy

Rovastar
Posts: 295
Joined: Wed May 05, 2004 9:25 am
Location: Derby/London, England

Post by Rovastar »

Got a look at this and used 2.6.8 beta

I get wha you men with the sign etc and aactually what I was after was a function atan2 with 2 parameters that you enter.

atan2(val1,val2)

Thus getting the 2 signed values of x and y. This would be most useful for polar to cart.

atan2(val1,val2) could be atan(y/x) with a more useful pi to -pi range.

Sorry when you said yo where adding atan2 I was presuming it would be a function that I have seen in other apps that does this. (In fact this is what I typed first the function form but obviously when I ran GF it did not look as I would have liked. :) )

There is an example of the code where I want a full(er) range I probably have to tweak it a lot to get the correct stuff out I would like but anyway have a wraparound effect for atan2 of pi to -pi would help. :)

//Rovastar & Geiss - Dynamic Swirls TEst
//modified from Ryan GEiss scenes for MilkDrop

A0="(0.01*rnd(50)) -0.25", //placement swirl 1 x co-ord
A1="(0.01*rnd(50)) -0.25", //placement swirl 1 y co-ord
A2="(0.01*rnd(50)) -0.25", //placement swirl 2 x co-ord
A3="(0.01*rnd(50)) -0.25", //placement swirl 2 y co-ord
//A4="0.01*(rnd(1)+1)", //swirl 1 power
//A5="0.01*(rnd(1)+1)", //swirl 2 power

D0 ="x+A0", //swirl location 1 x co-ord
D1 ="y+A1", //swirl location 1 y co-ord
D2 ="sqrt((D0*D0)+(D1*D1))", //newrad swirl 1
D3 = "atan2(D1/D0)", //newtheta swirl 1
//d3 ="atan2(D1,D0)",
D4 = "0.02/(D2+0.2)", //distance multiplier swirl 1

D5 ="x+A2", //swirl location 2 x co-ord
D6 ="y+A3", //swirl location 2 y co-ord
D7 ="sqrt((D5*D5)+(D6*D6))",//newrad swirl 2
D8 = "atan2(D6/D5)", //newtheta swirl2
//d8 = "atan2(D6,D5)",
D9 = "0.02/(D7+0.2)", //distance multipier swirl2

srcX = "x + d4*sin(d3-(1.5)) + d9*sin(d8+(1.5))",
srcY = "y + d4*cos(d3-(1.5)) + d9*cos(d8+(1.5))",

Vers=268,

User avatar
JayPro
Posts: 738
Joined: Sat May 01, 2004 10:51 pm
Location: Huntington Station, Long Island, New York

Fascinating!

Post by JayPro »

Sorry for the long time in responding, as I intended to for a bit.

This certainly paves the way for a whole host of interesting effects for the future. I trust that we'll see some that apply the arcsine/arccosine funcs as well.

Well done! Am I to understand that this is what the real appearance of the theta vector is supposed to be?

JwP

I don't know if this is what you're looking for; but I've pasted on the commented-out A4 & 5 variables by adding (+) them at the ends of D's 2,3, and 4 and D's 7, 8 and 9 respectively (IOW, a4 to the first triad and a5 to the second). It doesn't seem to mean any difference at all, save IMO to add a tad more consistency to the intended picture.

Just a thought...
"God is syntax."

Rovastar
Posts: 295
Joined: Wed May 05, 2004 9:25 am
Location: Derby/London, England

Post by Rovastar »

To be honest JayPro it is not there yet and Andy's engine doesn't allow for multiple parameter thus atan2 isn't right yet.

BUt the new engine is on it's way. :)

That said the equation for a rad in Cartisan works fine but you really need both for the full benefits.

User avatar
JayPro
Posts: 738
Joined: Sat May 01, 2004 10:51 pm
Location: Huntington Station, Long Island, New York

Tilting at Windmills...

Post by JayPro »

...Hopefully this means that we'll be able to support even more functions than before (cosec/csc, int, hyp, bln, sinh, cosh, tanh/atanh are some examples I can think of--if not vouch for in terms of what they mean--that I've seen in others' configs, esp those from Erich Kodotai...imagine if what both he and you must be really after comes to pass. Wow.). Also, we might see additional funcs specific to C++ like ceil(), since flor()--floor() in C++--is already supported?

Maybe? :lol:
"God is syntax."

User avatar
andy55
Site Admin
Posts: 569
Joined: Sat May 01, 2004 4:38 pm
Contact:

Post by andy55 »

Rovastar wrote:To be honest JayPro it is not there yet and Andy's engine doesn't allow for multiple parameter thus atan2 isn't right yet.

BUt the new engine is on it's way. :)

That said the equation for a rad in Cartisan works fine but you really need both for the full benefits.
Yeah, w/ the new engine will come all kinds of various build functions, including multi param ones. Ugh, I can't wait to get it up and running.

Andy

User avatar
JayPro
Posts: 738
Joined: Sat May 01, 2004 10:51 pm
Location: Huntington Station, Long Island, New York

This might be too late but...

Post by JayPro »

is there *any* way I can help with this?

Do I need to learn C++ in, say, a week or two?

If possible, would (at least one of) you be willing to act as a cyber-tutor of sorts to help me get a hang of this?

Do I need any sort of hardware that can facilitate the process?

This sounds too fascinating/tempting for me to let pass by...

I'd really like to know. I'm willing to channel out my self-fancied inability to understand mathematics if but for the sake of getting the general idea.

Oh, where to begin! :D
"God is syntax."

Rovastar
Posts: 295
Joined: Wed May 05, 2004 9:25 am
Location: Derby/London, England

Post by Rovastar »

Here is a list of some maths functions that I would find useful. Used in AVS and MilkDrop, etc and we based some of these within R4 as well.

With the use of if statements, etc the scripting can be more useful. Maybe not too useful for the static precalulated (more useful in a dynamic enviornment) delta maps but useful nevertheless.

int(var) Returns the integer value of 'var' (rounds toward zero)
abs(var) Returns the absolute value of var
sin(var) Returns the sine of the angle var (expressed in radians)
cos(var) Returns the cosine of the angle var
tan(var) Returns the tangent of the angle var
asin(var) Returns the arcsine of var
acos(var) Returns the arccosine of var
atan(var) Returns the arctangent of var
sqr(var) Returns the square of var
sqrt(var) Returns the square root of var
pow(var,var2) Returns var to the power of var2
exp(var) The same as pow(e, var), where e is Euler’s constant (2.7182..., the base of natural logarithms).
log(var) Returns the log base e of var
log10(var) Returns the log base 10 of var
sign(var) Returns the sign of var or 0
min(var,var2) Returns the smallest value
max(var,var2) Returns the greatest value
sigmoid(var,var2) Returns sigmoid function value of x=var (var2=constraint)
atan2(var,var2) Calculates the arctangent of (var/var2)
rand(var) Returns a random integer modulo 'var'; e.g. rand(4) will return 0, 1, 2, or 3.
band(var,var2) Boolean and, returns 1 if var or var2 is != 0
bor(var,var2) Boolean or, returns 1 if var or var2 is != 0
bnot(var) Boolean not, returns 1 if var = = 0 or 0 if var != 0
if(cond,vartrue,varfalse) If condition is nonzero, returns valtrue, otherwise returns valfalse
equal(var,var2) Returns 1 if var = var2, else 0
above(var,var2) Returns 1 if var > var2, else 0
below(var,var2) Returns 1 if var < var2, else 0

Hope you find it useful

Post Reply