create point betweem two points
显示 更早的评论
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
采纳的回答
NumberNewPoints = 3;
xvals = linspace(2, 10, NumberNewPoints+2);
yvals = linspace(5, 15, NumberNewPoints+2);
pts = [xvals(:), yvals(:)];
Now the points are the rows.
11 个评论
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
Which mechanism were you thinking of for moving the points?
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]
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
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.
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
pts(1,:) %x,y for starting point
pts(2,:) %x,y for intermediate point
pts(3,:) %x,y for final point
更多回答(1 个)
out = ([10,15]-[2,5])*(2*rand-1)+[2,5]
类别
在 帮助中心 和 File Exchange 中查找有关 Fixed-Point Designer 的更多信息
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!选择网站
选择网站以获取翻译的可用内容,以及查看当地活动和优惠。根据您的位置,我们建议您选择:。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- América Latina (Español)
- Canada (English)
- United States (English)
欧洲
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
