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
Walter Roberson
Walter Roberson 2012 年 7 月 15 日
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]
Majid Al-Sirafi
Majid Al-Sirafi 2012 年 7 月 15 日
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
Walter Roberson
Walter Roberson 2012 年 7 月 15 日
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. ;-)
Walter Roberson
Walter Roberson 2012 年 7 月 16 日
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 ExchangeMatrix Indexing についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by