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

 채택된 답변

Walter Roberson
Walter Roberson 2012년 7월 15일

2 개 추천

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

댓글 수: 11

Majid Al-Sirafi
Majid Al-Sirafi 2012년 7월 15일
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 2012년 7월 15일
Which mechanism were you thinking of for moving the points?
Majid Al-Sirafi
Majid Al-Sirafi 2012년 7월 15일
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 2012년 7월 16일
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 2012년 7월 16일
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 2012년 7월 16일
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 2012년 7월 16일
편집: Walter Roberson 2018년 1월 28일
pts(1,:) %x,y for starting point
pts(2,:) %x,y for intermediate point
pts(3,:) %x,y for final point

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Andrei Bobrov
Andrei Bobrov 2012년 7월 16일

0 개 추천

out = ([10,15]-[2,5])*(2*rand-1)+[2,5]

카테고리

도움말 센터File Exchange에서 Matrix Indexing에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by