[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Deviation in math functions
- From: roman.maire@...
- Date: Fri, 10 Feb 2012 08:18:11 +0000 (UTC)
Hi Everyone
I've got a problem here with the standard math functions:
Given a starting position, an angle and a distance, I'm trying to calculate the new position. But sometimes I get strange results. Ecamples:
angle = 180
originx = 100
originy = 100
distance = 100
x = (originx + (math.cos(math.rad(angle)) * distance))
y = (originy + (math.sin(math.rad(angle)) * distance))
print("x: ".. x ..", y: ".. y)
Output:
-> x: 0, y: 100
This works perfectly fine.
angle = 270
originx = 0
originy = 100
distance = 100
x = (originx + (math.cos(math.rad(angle)) * distance))
y = (originy + (math.sin(math.rad(angle)) * distance))
print("x: ".. x ..", y: ".. y)
Output:
-> x: -1.836970198721e-014, y: 0
I was expecting that x should be 0 too.
am I missing something here?
Kind regards,
Roman