comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: Looking for 3-D vector routines ( dot & cross product, ..) for arrays of [x,y,z]'s
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Re: Looking for 3-D vector routines ( dot & cross product, ..) for arrays of [x,y,z]'s [message #29598] Tue, 05 March 2002 11:29
James Kuyper is currently offline  James Kuyper
Messages: 425
Registered: March 2000
Senior Member
William Gallery wrote:

> I need a set of routines that operate on ***arrays*** of 3-D vectors
> (x, y, z), including:
> length of a vector
> dot- and cross- products
> included angle between two vectors
>
>
> Before I write my own, are there any out there already?

There aren't any such routines to work on arrays of vectors, but the
equivalent code is fairly simple:

seed = 12345L
a = randomn(seed, 3, 5)
b = randomn(seed, 3, 5)

dot_product = total(a*b,1)
lengtha = total(a^2,1)^0.5
lengthb = total(b^2,1)^0.5

; Warning: not protected against division by 0:
angle = acos(dot_product/(lengtha*lengthb)
; If calculating only the angle, this is slightly faster
; since there's only one sqrt() per row
angle = acos(dot_product/(total(a^2,1)*total(b^2,1))^0.5)

cross_prod = dblarr(3,5)
cross_prod(0,*) = a(1,*)*b(2,*)-a(2,*)*b(1,*)
cross_prod(1,*) = -a(0,*)*b(2,*)+a(2,*)*b(0,*)
cross_prod(2,*) = a(0,*)*b(1,*)-a(1,*)*b(0,*)
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Looking for 3-D vector routines ( dot & cross product, ..) for arrays of [x,y,z]'s
Next Topic: Re: Plotting error in IDL 5.5

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 15:54:23 PDT 2025

Total time taken to generate the page: 0.00523 seconds