Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!ecngs!feeder2.ecngs.de!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.012 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'line:': 0.07; 'length)': 0.09; 'rounding': 0.09; 'cc:addr:python-list': 0.10; 'subject:python': 0.11; '(x,': 0.16; 'angle': 0.16; 'binary,': 0.16; 'coordinates': 0.16; 'multiples': 0.16; 'string': 0.17; 'wrote:': 0.17; 'string,': 0.17; 'feb': 0.19; 'math': 0.20; 'trying': 0.21; 'subject:problem': 0.22; 'cc:2**0': 0.23; '15,': 0.23; 'errors': 0.23; 'cc:addr:python.org': 0.25; 'header:In- Reply-To:1': 0.25; 'values': 0.26; 'message-id:@mail.gmail.com': 0.27; 'url:mailman': 0.29; 'fri,': 0.30; 'point': 0.31; 'url:python': 0.32; 'skip:- 10': 0.32; 'url:listinfo': 0.32; 'getting': 0.33; 'received:google.com': 0.34; 'skip:: 10': 0.35; 'doing': 0.35; 'expected': 0.35; 'pm,': 0.35; 'received:209.85': 0.35; 'url:org': 0.36; '(i.e.': 0.36; 'scientific': 0.36; 'should': 0.36; 'why': 0.37; 'received:209': 0.37; 'subject:: ': 0.38; 'skip:( 30': 0.38; 'instead': 0.39; 'end': 0.40; 'url:mail': 0.40; 'times': 0.63; 'email addr:gmail.com': 0.63; '180': 0.84; '2013': 0.84; 'notion': 0.84; 'joel': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:in-reply-to:references:date:message-id :subject:from:to:cc:content-type; bh=YyLPVsaHH9CZ5mlK/CslWd7UbhtBmAhmkM0RHyT1SVA=; b=K3yEkfaY5BdnXpP4yhXZeDSWI2gaBdDUmyi5b/Xw1gOv1vE0irL6nKoMFTB5INAsSc 8dgm1PQEyMizwnGHV1ix90RXoWAilRKOSEHuEGGUVvu60ufVk46KFbNF6J+dBEikDvhb M7XagU5M7uD+VXxMq7VqmGBIOJSODV7d0mDXG7xIFAqPB07DirUmFndfIUUhtwZUAxYr Q9wT8rTKcELTcnsnbxSRSIhZH5GsjwxIrkG6dV0JC5PkfCgl4jI0BOr5qxLMdif1iICS byUdOxEzgVL+2i84G8v19JbwePYHO36yRWErD5Sw2C+RacWPb54MW4H1rFIomz3Jj/47 rdqg== MIME-Version: 1.0 X-Received: by 10.220.9.3 with SMTP id j3mr4772946vcj.56.1360957769846; Fri, 15 Feb 2013 11:49:29 -0800 (PST) In-Reply-To: References: Date: Fri, 15 Feb 2013 14:49:29 -0500 Subject: Re: python math problem From: Joel Goldstick To: Kene.Meniru@illom.org Content-Type: multipart/alternative; boundary=bcaec54ee0146d0e9e04d5c8acda Cc: "python-list@python.org" X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 95 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1360957772 news.xs4all.nl 6982 [2001:888:2000:d::a6]:38313 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:38955 --bcaec54ee0146d0e9e04d5c8acda Content-Type: text/plain; charset=UTF-8 On Fri, Feb 15, 2013 at 2:39 PM, Kene Meniru wrote: > I am trying to calculate the coordinates at the end of a line. The length > and angle of the line are given and I am using the following formula: > > x = (math.sin(math.radians(angle)) * length) > y = (math.cos(math.radians(angle)) * length) > > The following are sample answers in the format (x, y) to the given > length/angle values of the line: > > 120/0 = (0.0, 25.0) > 120/89 = (24.9961923789, 0.436310160932) > 120/90 = (25.0, 1.53075794228e-15) > This is not a string, it is scientific notion for 1.53... times 10 to the -15th power. Because of rounding errors caused by doing floating point math on in binary, you get a very small number instead of 0. > 120/91 = (24.9961923789, -0.436310160932) > > Why am I getting a string number instead of the expected answer for 120/90 > which should be (25.0, 0.0). This happens at all multiples of 90 (i.e. 180 > and 270) > > -- > > Kene > :::::::::::::::::: > KeMeniru@gmail.com > > -- > http://mail.python.org/mailman/listinfo/python-list > -- Joel Goldstick http://joelgoldstick.com --bcaec54ee0146d0e9e04d5c8acda Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable



On Fri, Feb 15, 2013 at 2:39 PM, Kene Meniru <= Kene.Meniru@illo= m.org> wrote:
I am trying to calculate the coordinates at = the end of a line. The length
and angle of the line are given and I am using the following formula:

x =3D (math.sin(math.radians(angle)) * length)
y =3D (math.cos(math.radians(angle)) * length)

The following are sample answers in the format (x, y) to the given
length/angle values of the line:

120/0 =C2=A0=3D (0.0, 25.0)
120/89 =3D (24.9961923789, 0.436310160932)
120/90 =3D (25.0, 1.53075794228e-15)

Th= is is not a string, it is scientific notion for 1.53... times 10 to the -15= th power.=C2=A0 Because of rounding errors caused by doing floating point m= ath on in binary, you get a very small number instead of 0.
120/91 =3D (24.9961923789, -0.436310160932)

Why am I getting a string number instead of the expected answer =C2=A0for 1= 20/90
which should be (25.0, 0.0). This happens at all multiples of 90 (i.e. 180<= br> and 270)

--

Kene
::::::::::::::::::
KeMeniru@gmail.com

--
http://mail.python.org/mailman/listinfo/python-list



--
--bcaec54ee0146d0e9e04d5c8acda--