programming forums Java Java JSRs Mobile Certification Databases Caching Books Engineering OS Languages Paradigms IDEs Build Tools Frameworks Products This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Sheriffs:
Saloon Keepers:
Bartenders:

# i finish building the fuction but in certain cases..

johny doe
Ranch Hand
Posts: 78
it works in all cases exept
when i tried to rotate the point (0,1) around the point (0,0)
180 degrees clock wise instead of giving me the value(0,-1)

it gives me

6.123233995736766E-17,-1.0

when i tried to rotate the point (0,1) around the point (0,0)
270 degrees clock wise instead of giving me the value(-1,0)

it gives me

-1.0,-1.2246467991473532E-16

when i tried to rotate the point (0,1) around the point (0,0)
0 degrees clock wise instead of giving me the value(0,1)

it gives me
6.123233995736766E-17,1.0

i dont know what this E number means
i dont know why it happening??

public void rotate(Point center,double angle)
{
double xi; //represents the temprary values of x (the rotated point) befoure we add the values of the center point
double yi; //represents the temprary values of y (the rotated point) befoure we add the values of the center point
xi=0;
yi=0;

double fi;
fi=0;

double beta;
beta=0;

angle=(angle/180)*PI;

double slope;

slope=(y-center.y)/(x-center.x);

fi=atan(slope);

beta=fi-angle;

x=center.x+xi;

y=center.y+yi;

}//end rotate

Ulf Dittmer
Rancher
Posts: 42972
73
The "E" signifies "times 10 to the Nth power", also known as scientific notation

So "6.123233995736766E-17" means 6.123233995736766 * 10^-17, which is something around 0.00000000000000006123233995736766. For your purposes you can probably just round off those numbers to the desired significance -maybe 10 digits- and the result will be zero.

As to why those numbers aren't exactly zero to begin with, have a look at #20 in the http://faq.javaranch.com/java/JavaBeginnersFaq.

[EJFH: Fix URL]
[ December 21, 2007: Message edited by: Ernest Friedman-Hill ]

Campbell Ritchie
Marshal
Posts: 56533
172
Well done. You appear to be doing a lot better than yesterday.

As Ulf Dittmer has told you, if you draw those figures on a graph, you won't see a difference between 0 and 6.123233995736766E-17!