From: Thomas Griffith on
Hi,

I have two 3-D points from which I can create a line using plot3. I would like to be able to extract a number n data points (equally spaced) that lie on the line between these two given points and store them in an n x 3 matrix.

How can this be achieved?

Thanks!
Thomas
From: us on
"Thomas Griffith" <thomas.e.griffith(a)vanderbilt.edu> wrote in message <huahm6$51f$1(a)fred.mathworks.com>...
> Hi,
>
> I have two 3-D points from which I can create a line using plot3. I would like to be able to extract a number n data points (equally spaced) that lie on the line between these two given points and store them in an n x 3 matrix.
>
> How can this be achieved?
>
> Thanks!
> Thomas

a hint:

help interp2; % <- and siblings...

us
From: John D'Errico on
"Thomas Griffith" <thomas.e.griffith(a)vanderbilt.edu> wrote in message <huahm6$51f$1(a)fred.mathworks.com>...
> Hi,
>
> I have two 3-D points from which I can create a line using plot3. I would like to be able to extract a number n data points (equally spaced) that lie on the line between these two given points and store them in an n x 3 matrix.
>
> How can this be achieved?

I think that us has misinterpreted your question,
as interp2 would not help you.

You CAN use an interpolation. A simple way is
just this. Given two points P1 and P2, both 1x3
vectors, that define the coordinates of the two
points.

t = linspace(0,1,n)';
A = (1-t)*P1 + t*P2;

Each row of A is a point on that line. I was not
sure from your question about one thing. As I
have done it, the first point in the array is P1,
the last point is P2, with the remainder of the
points equally spaced between them. If you
wanted n points that do NOT include P1 and P2
at the ends, then this would work:

t = linspace(0,1,n+2)';
t([1 end]) = [];
A = (1-t)*P1 + t*P2;

HTH,
John
From: Thomas Griffith on
"John D'Errico" <woodchips(a)rochester.rr.com> wrote in message <huaja3$kk6$1(a)fred.mathworks.com>...
> "Thomas Griffith" <thomas.e.griffith(a)vanderbilt.edu> wrote in message <huahm6$51f$1(a)fred.mathworks.com>...
> > Hi,
> >
> > I have two 3-D points from which I can create a line using plot3. I would like to be able to extract a number n data points (equally spaced) that lie on the line between these two given points and store them in an n x 3 matrix.
> >
> > How can this be achieved?
>
> I think that us has misinterpreted your question,
> as interp2 would not help you.
>
> You CAN use an interpolation. A simple way is
> just this. Given two points P1 and P2, both 1x3
> vectors, that define the coordinates of the two
> points.
>
> t = linspace(0,1,n)';
> A = (1-t)*P1 + t*P2;
>
> Each row of A is a point on that line. I was not
> sure from your question about one thing. As I
> have done it, the first point in the array is P1,
> the last point is P2, with the remainder of the
> points equally spaced between them. If you
> wanted n points that do NOT include P1 and P2
> at the ends, then this would work:
>
> t = linspace(0,1,n+2)';
> t([1 end]) = [];
> A = (1-t)*P1 + t*P2;
>
> HTH,
> John

John,

That worked perfectly! Thanks!

Thomas