From: Thomas Griffith on 4 Jun 2010 05:40 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 4 Jun 2010 05:53 "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 4 Jun 2010 06:08 "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 4 Jun 2010 06:24 "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
|
Pages: 1 Prev: NN testing code Next: code obfuscation (no p-code is not enough) |