"Kent Johnson" <[EMAIL PROTECTED]> wrote
Usually based on magnitude alone.
That seems a pretty strange definition of equal, that makes (1, 0)
== (0, 1).
Yes I know! But actually in many engineering situations where phase
is not important it's a good first approximation (for example power
ca
On Wed, Jul 9, 2008 at 2:17 PM, Alan Gauld <[EMAIL PROTECTED]> wrote:
> "Kent Johnson" <[EMAIL PROTECTED]> wrote
>>
>> That just raises the question of how do complex numbers compare?
>
> Usually based on magnitude alone.
> That's why I said the results would be equivalent to the length of a point
"Kent Johnson" <[EMAIL PROTECTED]> wrote
That just raises the question of how do complex numbers compare?
Usually based on magnitude alone.
That's why I said the results would be equivalent to the length of
a point approach. You assume that any point on the same sperical
locus is equal. At
On Wed, Jul 9, 2008 at 3:05 AM, Alan Gauld <[EMAIL PROTECTED]> wrote:
>
> Rather than comparing in that manner I'd take a different approach.
> I'd measure the length from the origin thus any point that was inside
> the circle upon whose ciorcumference the point sits is less than
> the point. Any p
"Christopher Spears" <[EMAIL PROTECTED]> wrote
def __cmp__(self, other):
if self.x == other.x and self.y == other.y:
return 0
elif self.x < other.x and self.y < other.y:
return -1
elif self.x > other.x and self.y > other.y:
return 1
Rather than comparing in that manner I'd
On 09/07/2008, Paul McGuire <[EMAIL PROTECTED]> wrote:
> > def length(self):
> > dx,dy = self.p1 - self.p2
> > return (dx**2 + dy **2) ** 0.5
>
> How about:
>
> def length(self):
> return math.hypot( *(self.p1 - self.p2) )
>
> Compiled C code will be much faster than squaring and
> def length(self):
> dx,dy = self.p1 - self.p2
> return (dx**2 + dy **2) ** 0.5
How about:
def length(self):
return math.hypot( *(self.p1 - self.p2) )
Compiled C code will be much faster than squaring and square rooting.
-- Paul
___
T
On Tue, Jul 8, 2008 at 6:29 PM, Christopher Spears
<[EMAIL PROTECTED]> wrote:
> I have been reading everyone's comments on my line class. I have decided to
> implement some of the suggestions. Someone suggested that I create a
> Point.__cmp__ method. Here is what I have so far:
>
> def __cmp__
On Tue, Jul 8, 2008 at 3:29 PM, Christopher Spears <[EMAIL PROTECTED]>
wrote:
> I have been reading everyone's comments on my line class. I have decided
> to implement some of the suggestions. Someone suggested that I create a
> Point.__cmp__ method. Here is what I have so far:
>
> def __cmp__(
I have been reading everyone's comments on my line class. I have decided to
implement some of the suggestions. Someone suggested that I create a
Point.__cmp__ method. Here is what I have so far:
def __cmp__(self, other):
if self.x == other.x and self.y == other.y:
return 0
"Christopher Spears" <[EMAIL PROTECTED]> wrote
class Point(object):
def __init__(self, x=0.0,y=0.0):
self.x = float(x)
self.y = float(y)
def __repr__(self):
coord = (self.x,self.y)
return coord
You could add a couple of methods here to get deltaX and
deltaY values Or ev
>
> > def __init__(self,p1,p2):
> > self.p1 = p1
> > self.p2 = p2
> >
> > And since a line should not have zero length (although you might argue
> > with that!) you could also check if
> > p1==p2
>
> In this case he should define Point.__cmp__() so the comparison is by
value rather than iden
On Tue, Jul 8, 2008 at 4:01 AM, Alan Gauld <[EMAIL PROTECTED]> wrote:
> def __init__(self,p1,p2):
> self.p1 = p1
> self.p2 = p2
>
> And since a line should not have zero length (although
> you might argue with that!) you could also check if
> p1==p2
In this case he should define Point.__cmp__
On Tue, Jul 8, 2008 at 12:52 AM, Christopher Spears
<[EMAIL PROTECTED]> wrote:
> For problem 13-6 out of Core Python Programming, I created a line class that
> consists of two points. The line class has the following methods: __repr__,
> length, and slope. Here is the code:
>def __repr__(s
"Christopher Spears" <[EMAIL PROTECTED]> wrote
class Point(object):
def __init__(self, x=0.0,y=0.0):
class Line(object):
def __init__(self, p1, p2):
self.p1 = Point(x1,y1)
self.p2 = Point(x2,y2)
This is wrong I suspect.
You are passing two point objects into the constructor b
On 08/07/2008, Christopher Spears <[EMAIL PROTECTED]> wrote:
> Basically, if the two the x values are the same, I will get a
> ZeroDivisionError. A line in this
> case would simply point straight up. What would slope be in this case? I
> will admit that
> this is probably a math problem not a
For problem 13-6 out of Core Python Programming, I created a line class that
consists of two points. The line class has the following methods: __repr__,
length, and slope. Here is the code:
#!/usr/bin/python
import sys,math
class Point(object):
def __init__(self, x=0.0,y=0.0):
se
17 matches
Mail list logo