[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Deviation in math functions
- From: HyperHacker <hyperhacker@...>
- Date: Fri, 10 Feb 2012 01:52:16 -0700
On Fri, Feb 10, 2012 at 01:18, <roman.maire@besonet.ch> wrote:
> 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
>
Look up floating point mathematics.
--
Sent from my toaster.