[Edu-sig] python satacad: class 6
Kirby Urner
urnerk at qwest.net
Sun Feb 20 04:23:57 CET 2005
> -----Original Message-----
> From: Arthur [mailto:ajsiegel at optonline.net]
> Sent: Saturday, February 19, 2005 6:57 PM
> To: 'Kirby Urner'; edu-sig at python.org
> Subject: RE: [Edu-sig] python satacad: class 6
>
...
> And what Klein prescribes in the end sounds much like a primer on the
> underlying mathematics and ideas which we now know as the fundamentals of
> computer vector graphics. Except that we tend to know these ideas, and
> teach them, out of the their historical and intellectual context.
Yeah, I wondered if you were referring to Quaternions and see from your
concluding quote that you were.
As it happens, the "more fully developed vector class" I was describing is
pretentious in just this way: if you multiply by a scalar, the vector
elongates or shrinks, like any good little vector. But if you try to
multiply by another vector, well then, both suddenly become quaternions at
that point -- though the result is returned as a vector.
def __mul__(self, other):
"""
Might be just scalar multiplication, but if the arg is another
vector, let's go through the motions of quaternion * quaternion
"""
if type(other) == type(self): # treat mul as quaternion mul
# (v1 x v2) + (s1*v2) + (s2*v1)
newv = self.cross(other) + (self.s * other) + (other.s * self)
# s1*s2 - v1.v2 where s1 is self.s, v1 is self.v
newv.s = (self.s * other.s) - self.dot(other)
return newv
if type(other) in [type(1.0), type(1)]: # or do scalar mul
return Vector3d(self.x * other, self.y * other, self.z * other)
__rmul__ = __mul__
http://www.4dsolutions.net/satacad/pytools/ -- see vector.py
But I didn't get into this at all with the kids today.
There's some excellent book on the history of vectors, one of those Dover
books -- talks about how the Gibbs-Heaviside approach gradually took hold
and that's what we generally taught in the 1900s. But computer gaming
helped quaternions make a come back. I used to post about this stuff quite
a bit -- buried in the Math Forum archives probably.
Yeah, here's the book, listed in the bibliography on that Quaternions page
at MathWorld:
http://www.amazon.com/exec/obidos/tg/detail/-/0486679101/
Kirby
More information about the Edu-sig
mailing list