triangle
7 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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
0 comentarios
Respuestas (2)
Walter Roberson
el 19 de Feb. de 2011
Please return to your previous question on this topic and edit the additional information in to that, and delete this duplicate question.
0 comentarios
Matt Fig
el 19 de Feb. de 2011
Another vote to update your topic and don't forget to DELETE this topic!
0 comentarios
Ver también
Categorías
Más información sobre Axes Appearance en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!