|
|
|
#1 | |
|
Senior Member
Join Date: Jan 2003
Location: Romania
Posts: 126
|
Math.cos not accurate! Help!
Hi everyone
I have the following issue which is driving me nuts. I've written these 2 functions for returning the end coordinates of a line, when you know the starting coordinates, angle and length. So, x1 and y1 are the starting point's coordinates, u = angle and l = length. Code:
function degToRad(u) {
return((u*Math.PI)/180);
}
function angleLineX(x1, y1, l, u) {
u = degToRad(u);
x2 = l*Math.cos(u);
x2 = x1 + x2;
return(x2);
}
function angleLineY(x1, y1, l, u) {
u = degToRad(u);
y2 = l*Math.sin(u);
y2 = y1 - y2;
return(y2);
}
These functions usually work pretty well, but i came across a few values which don't seem to work. Code:
a = angleLineX(0, 0, 864, 89.67); b = angleLineX(0, 0, 864, 89.66); trace(a + " - " + b); Code:
0.69 - 9.33 Code:
a = angleLineX(0, 0, 864, 89.68); b = angleLineX(0, 0, 864, 89.67); trace(a + " - " + b); Code:
0.69 - 0.69 Otherwise, from 89.67 to 89.68 there's virtually no change Can someone please help me? Am i doing something wrong? I'm guessing the cos function is not very accurate, as you can see from the help file Quote:
Also, can anyone sugesst a fix or alternative to doing that? Thanks
__________________
http://www.fishstudio.ro |
|
|
|
|
|
|
#2 |
|
Senior Member
Join Date: Jan 2003
Location: Romania
Posts: 126
|
fixed. thanks
It wasn't a problem with the cos function but with a Math.round i was using when converting from degrees to radians, which i forgot about.
__________________
http://www.fishstudio.ro Last edited by olias32; 09-07-2009 at 11:03 AM. |
|
|
|
![]() |
|
||||||
| Thread Tools | Search this Thread |
| Display Modes | |
|
|