フィルターのクリア

Why are those lines not drawn?

2 ビュー (過去 30 日間)
Dimitar Slavchev
Dimitar Slavchev 2021 年 3 月 16 日
コメント済み: Dimitar Slavchev 2021 年 4 月 10 日
I am using the following code to draw a triangle ABC and the medians AD1, BD2, CD3. A1, B1, C1 are points along each median that are 1/3 away from the angle the median starts from. I use line to draw the ABC triangle and the medians, but Matlab refuses to draw two of the medians. I did check the values by hand and they seem fine. All of the D and [ABC]1 points seem to be right were I want them.
Why aren't all three medians drawn?
A = [1; 0.8384];
B = [1; 1];
C = [0.8384; 1];
D1 = (B + C)/2;
D2 = (A + C)/2;
D3 = (A + B)/2;
A1 = A + (D1 - A)/3;
B1 = B + (D2 - B)/3;
C1 = C + (D3 - C)/3;
line(A,B);
hold on;
line(B,C);
line(C,A);
% Draws medians
line(A,D1);
line(B,D2);
line(C,D3);
plot(D1(1), D1(2), 'kx');
plot(D2(1), D2(2), 'kx');
plot(D3(1), D3(2), 'kx');
plot(A1(1), A1(2), 'kx');
plot(B1(1), B1(2), 'kx');
plot(C1(1), C1(2), 'kx');
hold off;
Picture is:

採用された回答

Dimitar Slavchev
Dimitar Slavchev 2021 年 3 月 16 日
編集済み: Dimitar Slavchev 2021 年 3 月 16 日
OK, glorious user error, as expected.
When using line one shouldn't do:
line(A,B);
But instead put the x values in the first argument and the y values in the second. As in:
line([A(1) B(1)], [A(2) B(2)]);
Unfortunatelly my ABC triangle was drawing right with the wrong data and that threw me off.
I saw the answer in this question:

その他の回答 (1 件)

Cris LaPierre
Cris LaPierre 2021 年 3 月 16 日
Check your values again.
line(A,D1); appears as expected
line(B,D2); is a single point (Both B values are the same, and both D2 values are the same, so no line)
line(C,D3); is the the same as line(A,D1), just in reverse. So it is getting plotted, but on top of an existing line.
  1 件のコメント
Dimitar Slavchev
Dimitar Slavchev 2021 年 4 月 10 日
I was using line wrong.
I.e. I was expecting that:
line(A,B);
should write a line form A to B, which is wrong.
But instead it should be:
line([A(1) B(1)], [A(2) B(2)]);

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

カテゴリ

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

タグ

製品


リリース

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by