triangle

3 次查看(过去 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 中查找有关 Discrete Math 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by