Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > python math problem

Reply
Thread Tools

python math problem

 
 
Kene Meniru
Guest
Posts: n/a
 
      02-15-2013
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
::::::::::::::::::
http://www.velocityreviews.com/forums/(E-Mail Removed)

 
Reply With Quote
 
 
 
 
John Machin
Guest
Posts: n/a
 
      02-16-2013
On Feb 16, 6:39*am, Kene Meniru <(E-Mail Removed)> 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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Math.random() and Math.round(Math.random()) and Math.floor(Math.random()*2) VK Javascript 15 05-02-2010 03:43 PM
Math.min and Math.max for byte / short Philipp Java 9 07-23-2008 12:37 AM
math.h trig functions questions (and some forgotten high school math) Mark Healey C Programming 7 05-22-2006 10:42 AM
Re: Is still math.h the C++ math library ? AciD_X C++ 4 04-01-2004 07:29 PM
Why can I not use: Math a=new Math(); chirs Java 18 03-02-2004 06:00 PM



Advertisments