• Post Reply Bookmark Topic Watch Topic
  • New Topic

i finish building the fuction but in certain cases..  RSS feed

 
johny doe
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
double rad;
xi=0;
yi=0;
rad=0;

rad=distance(center);
double fi;
fi=0;

double beta;
beta=0;
rad=distance(center);

angle=(angle/180)*PI;

double slope;

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

fi=atan(slope);

beta=fi-angle;




xi=rad*cos(beta);
yi=rad*sin(beta);
x=center.x+xi;

y=center.y+yi;





}//end rotate
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!