Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #38952 > unrolled thread
| Started by | Kene Meniru <Kene.Meniru@illom.org> |
|---|---|
| First post | 2013-02-15 14:39 -0500 |
| Last post | 2013-02-15 18:51 -0800 |
| Articles | 2 — 2 participants |
Back to article view | Back to comp.lang.python
python math problem Kene Meniru <Kene.Meniru@illom.org> - 2013-02-15 14:39 -0500
Re: python math problem John Machin <sjmachin@lexicon.net> - 2013-02-15 18:51 -0800
| From | Kene Meniru <Kene.Meniru@illom.org> |
|---|---|
| Date | 2013-02-15 14:39 -0500 |
| Subject | python math problem |
| Message-ID | <mailman.1839.1360957179.2939.python-list@python.org> |
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) 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
[toc] | [next] | [standalone]
| From | John Machin <sjmachin@lexicon.net> |
|---|---|
| Date | 2013-02-15 18:51 -0800 |
| Message-ID | <cc2c01c2-6e5e-4148-b1bc-f3b82b2d50ed@m9g2000pby.googlegroups.com> |
| In reply to | #38952 |
On Feb 16, 6:39 am, Kene Meniru <Kene.Men...@illom.org> wrote: > x = (math.sin(math.radians(angle)) * length) > y = (math.cos(math.radians(angle)) * length) A suggestion about coding style: from math import sin, cos, radians # etc etc x = sin(radians(angle)) * length y = cos(radians(angle)) * length ... easier to write, easier to read.
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web