triangle

조회 수: 6 (최근 30일)
WONG SIAN
WONG SIAN 2011년 2월 19일
A figure shows a triangle defined by the vertex coordinates (x1 ,y1 ) ,(x2 ,y2 ) , and (x3 ,y3 ). What command will interactively prompt a user for x and y coordinates at each of the triangle vertices. then how about draw the triangle and label it vertices. Next is compute and print the area of the triangle and its perimeter.
My solution is like this, please check for me ya...
x1=input('x1=');
y1=input('y1=');
x2=input('x2=');
y2=input('y2=');
x3=input('x3=');
y3=input('y3=');
v1=[x1 y1];
v2=[x2 y2];
v3=[x3 y3];
a=sqrt((x1-x2)^2+(y1-y2)^2);
b=sqrt((x2-x3)^2+(y2-y3)^2);
c=sqrt((x3-x1)^2+(y3-y1)^2);
if a > 0 & b > 0 & c > 0 & (a + b > c) & (a + c > b) & (b + c > a)
s=(a+b+c)/2;
Area=sqrt(a*(s-a)*(s-b)*(s-c))
Perimeter=a+b+c
plot([x1 x2 x3 x1],[y1 y2 y3 y1])
title('Triangle')
xlabel('x axis')
ylabel('y axis')
text(x1,y1,sprintf('(%d,%d)',x1,y1))
text(x2,y2,sprintf('(%d,%d)',x2,y2))
text(x3,y3,sprintf('(%d,%d)',x3,y3))
else
disp('Not a triangle, please reinsert')
end

답변 (2개)

Walter Roberson
Walter Roberson 2011년 2월 19일
Please return to your previous question on this topic and edit the additional information in to that, and delete this duplicate question.

Matt Fig
Matt Fig 2011년 2월 19일
Another vote to update your topic and don't forget to DELETE this topic!

카테고리

Help CenterFile Exchange에서 Axes Appearance에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by