Hi every one
I have two points, for example
(2,5)-(10,15)... how can I create a new point between them???
thanks a loot
majid

 Réponse acceptée

Walter Roberson
Walter Roberson le 15 Juil 2012

2 votes

NumberNewPoints = 3;
xvals = linspace(2, 10, NumberNewPoints+2);
yvals = linspace(5, 15, NumberNewPoints+2);
pts = [xvals(:), yvals(:)];
Now the points are the rows.

11 commentaires

Majid Al-Sirafi
Majid Al-Sirafi le 15 Juil 2012
thank you dear walter
now how can I move the created points ( for example i want to move one created point) between two original points
thanks dear
Walter Roberson
Walter Roberson le 15 Juil 2012
Which mechanism were you thinking of for moving the points?
Majid Al-Sirafi
Majid Al-Sirafi le 15 Juil 2012
dear walter
the mechanism is straight moving (that means the created points move between (2,5) and (10,15) and do not exceed them)
thanks dear
Let the original point be (x1,y1) and the final point be (x2,y2), and let t be a proportion of the time for the movement (i.e. t=0 when at the starting point, t=1 when at the ending point.) Then,
newpoints = (x1(:) + (x2(:)-x1(:)) .* t, y1(:) + (y2(:)-y1(:)) .* t]
please dear let dear apply the equation with the following data let p1(2,5) and p2(10,15) and we want to move p1 by 1 time to p2 so,
newpoints = [2 + (10-2) .*2, 5 + (15-5) .*2]
newpoints = 18 25
x=18 and y=25 ... is this ok ???
thanks dear
thanks a lot dear
You used 2 for your time t, not 1. t should be the portion along the line segment that you want, not the absolute time.
If you are starting at time 0 and ending at time Tmax, then the "t" of the equation should be the current time divided by Tmax:
newpoints = (x1(:) + (x2(:)-x1(:)) .* T/Tmax, y1(:) + (y2(:)-y1(:)) .* T/Tmax]
For example if you are at time T now and your last time for the movement is Tmax = 7.3, then you would have
newpoints = (x1(:) + (x2(:)-x1(:)) .* T/7.3, y1(:) + (y2(:)-y1(:)) .* T/7.3]
Majid Al-Sirafi
Majid Al-Sirafi le 16 Juil 2012
Please dear walter
apply that with the actual values please I have p1(2,5) and p2(10,15) and i want to move from p1 to p2, apply that with your equation, and what the new value of x and y
Image Analyst
Image Analyst le 16 Juil 2012
Walter just loves it when people call him dear. ;-)
x = 2 + 8 .* T/Tmax;
y = 5 + 10 .* T/Tmax;
Where T is the time since the start, and Tmax is the time at which you want to reach the second point.
Majid Al-Sirafi
Majid Al-Sirafi le 16 Juil 2012
dear watler according to your code
NumberNewPoints = 3;
xvals = linspace(2, 10, NumberNewPoints+2);
yvals = linspace(5, 15, NumberNewPoints+2);
pts = [xvals(:), yvals(:)];
but I choose NumberNewPoints = 1;
so, the new created point is (6,10) how can I move this created point between p1(2,5) and p2(10,5).. that means i want to move this created point to p1 at first state , and move the created point to p2 at a second state,and the movement time is 2. But this movement do not exceed P1 and p2
thanks a lot
Walter Roberson
Walter Roberson le 16 Juil 2012
Modifié(e) : Walter Roberson le 28 Jan 2018
pts(1,:) %x,y for starting point
pts(2,:) %x,y for intermediate point
pts(3,:) %x,y for final point

Connectez-vous pour commenter.

Plus de réponses (1)

Catégories

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by