フィルターのクリア

How can I plot a new vector that have a relative length of another?

2 ビュー (過去 30 日間)
Marco Branco
Marco Branco 2013 年 10 月 12 日
コメント済み: Marco Branco 2013 年 10 月 12 日
I have two points with coordinates in 3d space, and now I want to plot other vector with the same origin and with 30% of the length of the first one. For that I create a new ending point representing 30% of the coordinates of the 2nd point. This code work well if I have coordinates without decimal places, but in my data every coordinates have decimal places. Could you help me? Thanks. The code that I have is:
p1=[70.025, 0.574, 0.370];
p2=[140.590, -0.431, -0.226];
x1=[p1(1) p2(1)];
y1=[p1(2) p2(2)];
z1=[p1(3) p2(3)];
p3=[(p1(1)+p2(1)*0.3), (p1(2)+p2(2)*0.3), (p1(3)+p2(3)*0.3)];
x2=[p1(1) p3(1)];
y2=[p1(2) p3(2)];
z2=[p1(3) p3(3)];
hold on
plot3(x1, y1, z1)
plot3(x2, y2, z2, 'r')
hold off
  2 件のコメント
Azzi Abdelmalek
Azzi Abdelmalek 2013 年 10 月 12 日
編集済み: Azzi Abdelmalek 2013 年 10 月 12 日
Why decimals are a problem?
Marco Branco
Marco Branco 2013 年 10 月 12 日
編集済み: Marco Branco 2013 年 10 月 12 日
Thanks for your fast response. Because from my experiments with the code, I change the coordinates of the points to p1=[0, 0, 0]; p2=[10, -10, 10], and the plot became OK. I assume that decimal places make the propotion (of x,y and z coordinates) slight different. But it's just an opinion.

サインインしてコメントする。

採用された回答

Azzi Abdelmalek
Azzi Abdelmalek 2013 年 10 月 12 日
編集済み: Azzi Abdelmalek 2013 年 10 月 12 日
You can write
p3=p1+0.3*p2
  3 件のコメント
Azzi Abdelmalek
Azzi Abdelmalek 2013 年 10 月 12 日
Because
p3=p1+0.3*p2
%is not corresponding to your question, try
p3=p1+(p2-p1)*.3
Marco Branco
Marco Branco 2013 年 10 月 12 日
Perfect. Thanks.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeAnnotations についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by