Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Topic: Access to float coordinates in a 3D matrix
Replies: 10   Last Post: Dec 3, 2012 5:16 PM

 Messages: [ Previous | Next ]
 Javier Posts: 61 Registered: 4/26/11
Re: Access to float coordinates in a 3D matrix
Posted: Dec 3, 2012 10:39 AM

dpb <none@non.net> wrote in message <k9iei4\$g15\$1@speranza.aioe.org>...
> On 12/3/2012 8:11 AM, Javier wrote:
> ...
>

> >> > I use
> >> > x = x0 + t*dx
> >> > y = y0 + t*dy
> >> > z = z0 + t*dz
> >> > with t: 0:0.1:1, and d the direction vector.
> >> > This is the value of the coordinate isn't it?
> >> >

> ...
>

> > This are the first values for x: x(1),x(2) and x(3): 3,54551732809566
> > 3,63234837121917 3,71917941434267 3.
> > They are floating points because I have a decimal resolution. If for
> > example I want to acces Structures (x(1),y(1),z(1)), I can't.

>
> Well, no, you can't. At the command line...from your values
>

> >> t= 0:0.1:1;
> >> d0=3.54551732809566;
> >> dx=0.0868310431235;
> >> x=d0+t*dx

> x =
> Columns 1 through 7
> 3.5455 3.5542 3.5629 3.5716 3.5802 3.5889 3.5976
> Columns 8 through 11
> 3.6063 3.6150 3.6237 3.6323

> >>
>
> Note that x is a row vector of 10 elements. You can't have indices that
> aren't integers--what would the 3.5542...th entry in x be? The question
> makes no sense posed that way.
>
> What, specifically, are you trying to do that you're trying to write
> x(a_x_value) instead of x(an_index_value)?
>
> If you're trying to locate where within the array a particular value is
> located, you can use find() or logical addressing (subject to the
> caveats that equality-testing for floating point is subject to precision
> problems so that you may not find the result if do exact comparisons).
>
> At the command line again...
>

> >> ix=find(t==0.3)
> ix =
> []
>
> Note above returned []...what's up w/ that? Let's see...
>

> >> t(4)-0.3
> ans =
> 5.5511e-017
>
> Ah, note the small discrepancy between the value of approximately 0.3
> that you obtained from the floating point construction used to build the
> t vector and that which was converted to internal representation when
> typed in '0.3' at the command line...this is normal and one has to be
> sure to deal with it when using floating point.
>
> So, let's try something else...
>

> >> ix=find(abs(t-0.3)<1E-6)
> ix =
> 4

> >> x(ix)
> ans =
> 3.5716

> >>
>
> Hopefully that will clarify the problem you're having. The lesson to
> learn is
>
>
> A) There _can't_ be anything but an integer array index
>
> B) Floating point comparisons aren't exact
>
> Again, clarify what you're _really_ trying to do that causes you to
> write what you've written...
>
> --

Thank you both. I explain better my problem: using the equations for a 3D line, I obtain the vectors x, y and z of type double, which are the coordinates of the structure (Images, a 3D matrix) that I want to study.
I have horizontal, diagonal and vertical lines.
For example,
I need to evaluate the coordinate x(1)= 3.56 y(1) = 8.56 z(1)= 58.2 but really this isn't any voxel. How could I obtain the coordinates of the closest voxel, in order to evaluate
Images (x(1),y(1),z(1))?

Date Subject Author
12/3/12 Javier
12/3/12 Nasser Abbasi
12/3/12 Javier
12/3/12 Javier
12/3/12 Nasser Abbasi
12/3/12 Javier
12/3/12 Nasser Abbasi
12/3/12 dpb
12/3/12 Javier
12/3/12 dpb
12/3/12 Steven Lord