Strange Problem

if(personality == 0){

pangle = Math.atan((pz - z)/(px - x));

temp = Math.toDegrees(pangle);

System.out.println(temp);

}

Will output the correct angle.

publicvoid update(float px,float py,float pz){

if(personality == 0){

pangle = Math.atan((pz - z)/(px - x));

temp = Math.toDegrees(pangle);

System.out.println(temp);

x = (float)(x + (SPEED * Math.cos(pangle)));

if((temp == 90) || (temp == 270)){

x = x;

}

z = (float)(z + (-1 * (SPEED * Math.sin(pangle))));

y = y;

}

Outputs NaN for the angle? Why is this. To me this is extremely strange since i have changed nothing before the output statement, only after it.

Any help would be greatly appreciated!

[1340 byte] By [NickyP101a] at [2007-10-2 13:22:15]
# 1
Math.atan() will return NaN if its argument is NaN. In your case thiswould occur if any of x, z, pz or px are NaN or if px==x.It might be a good idea to print the values of these 4 variables as wellas temp.
pbrockway2a at 2007-7-13 10:58:57 > top of Java-index,Java Essentials,Java Programming...
# 2
Math.atan2() is a good alternative if x can be equal to px.kind regards,Jos
JosAHa at 2007-7-13 10:58:57 > top of Java-index,Java Essentials,Java Programming...
# 3
Haha you were both right :)Thanks guys, really wasnt thinking very well then.Cheers, Nick
NickyP101a at 2007-7-13 10:58:57 > top of Java-index,Java Essentials,Java Programming...