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

Home » Public Forums » archive » Programming style
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: Programming style [message #11736 is a reply to message #3375] Sat, 16 May 1998 00:00 Go to previous messageGo to previous message
pford is currently offline  pford
Messages: 33
Registered: September 1996
Member
In article <355CAD61.6BF75748@astrosun.tn.cornell.edu>, "J.D. Smith"
<jdsmith@astrosun.tn.cornell.edu> wrote:

> Patrick V. Ford wrote:
>>
>> I have a general style/algorithm question.
>>
>> I want to plot in a 3-D array an ellipsoid within an in ellipsoid where the
>> voxels between the boundaries are non-zero and else where zero.
>>
>> The general function is (x/a)^2 + (y/b)^2 + (z/c)^2 = 1.0
>>
>> I have already done this using for loops and conditional statements but it
>> occurred to me that there may be some IDL matrix-boolean logic combination
>> that could accomplish this in a faster and more 'elegant' fashion.
>>
>> I am now open for suggestions?
>>
>> Thanks in advance.
>>
>> Patrick Ford, MD
>> Department of Radiology
>> Baylor College of Medicine
>> pford@bcm.tmc.edu
>
> How about:
>
> recast as:
>
> Eq. 1: z^2+(x/e11)^2+(y/e21)^2 z^2=c1^2 (outer ellipse)
> Eq. 2: z^2+(x/e12)^2+(y/e22)^2 z^2=c2^2 (inner ellipse)
>
> let your array be nx by ny by nz.
>
> Then:
>
> z=findgen(nx*ny*nz)
> x2=((z mod (nx*ny)) mod nx-nx/2)^2
> y2=((z mod (nx*ny))/nx-ny/2)^2
> z2=((temporary(z)/(nx*ny)) - nz/2)^2
> array=bytarr(nx,ny,nz)
> array[where(z2+x2/e11^2+y2/e21^2 le c1^2 AND z2+x2/e12^2+y2/e22^2 ge
> c2^2)]=1b
>
> Note the two ellipses are centered on the midpoint of the array and are
> concentric. This can be modified by changing the subtracted value in
> each of x2,y2,z2. Definitely faster than loops. Elegance is in the eye
> of the beholder, though.
>
> NB: The x,y, and z index vectors must be floats, since for 3-d
> data,indices get large pretty quick. E.g. 100x100x100 would choke with
> longs (since 100^3^2=10^12=2^39.86!). This introduces some "fuzziness"
> at the boundaries due to roundoff. You can throw in a floor() statement
> to eliminate this if you really want.
>
> JD
>
> --
> J.D. Smith |*| WORK: (607) 255-5842
> Cornell University Dept. of Astronomy |*| (607) 255-4083
> 206 Space Sciences Bldg. |*| FAX: (607) 255-5875
> Ithaca, NY 14853 |*|

Interesting. I am going to have to think about this since it is not
immediately obvious to me. The maximum size of the cube I am working with
is 64X64X64 ( x8 since it is a cyclical dynamic objec) with the actual
object a lot smaller. I am actually using a hemi ellipsoid to grossly
represent the heart muscle of the left ventrical of the heart in a
radionuclide myocardial perfusion image. Fuzziness for this 'model' is
actually an advantage.

--
Patrick Ford
pford@bcm.tmc.edu
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Previous Topic: PS_FORM, other new IDL programs available
Next Topic: Re: spawning to my dir, not IDL dir !DIR

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

Current Time: Fri Oct 17 21:31:34 PDT 2025

Total time taken to generate the page: 0.00308 seconds