home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
El Mac 9
/
El Mac 9.iso
/
Shareware
/
Applications
/
MathPad 2.4
/
Examples
/
incl
/
vector ops
< prev
Encoding:
Amiga
Atari
Commodore
DOS
FM Towns/JPY
Macintosh
Macintosh JP
NeXTSTEP
RISC OS/Acorn
UTF-8
Wrap
Text File
|
1995-04-30
|
695 b
|
20 lines
|
[
TEXT/MPad
]
-- Arrays can be used to represent vectors. Addition, subtraction and multiplication by a scalar can be done directly. The following functions implement other basic vector operations.
dot(A,B) = sum(A[i]*B[i],i,1,count(A))
magnitude(A) = sqrt(dot(A,A))
cross(A,B) = {A[2]*B[3]-A[3]*B[2], -- 3D only
A[3]*B[1]-A[1]*B[3],
A[1]*B[2]-A[2]*B[1]}
-- cartesian to spherical coordinates
spherical(A) = {magnitude(A),
acos(A[3]/magnitude(A)),
atan2(A[2],A[1])}
-- spherical to cartesian coordinates
cartesian(r,theta,phi) = {r*sin(theta)*cos(phi),
r*sin(theta)*sin(phi),
r*cos(theta) }