Calculate the area of geometry

조회 수: 40 (최근 30일)
Minh
Minh 2022년 9월 30일
댓글: Minh 2022년 9월 30일
I have a difficult problem and I need help, "Write a function to calculate the area and perimeter of shapes: triangle, rectangle, circle?"
  댓글 수: 2
Minh
Minh 2022년 9월 30일
@Walter Rober i read it , i just want to say this problem is too difficult for me , i want to combine the same script but i can only do one idea calculate the area of each shape.

댓글을 달려면 로그인하십시오.

답변 (3개)

Walter Roberson
Walter Roberson 2022년 9월 30일
The first thing you need to do is decide how the user is going to represent the specific shape for calculation purposes.
  • are you going to have them input coordinates of each point?
  • are you going to have them input parameters such as height and width of the square, or radius of the circle?
  • are you going to have them input side lengths for the triangle? Side Angle Side ? From one side and two angles https://sciencing.com/calculate-triangle-one-side-given-8464316.html ? From three angles?
  • are you going to have the user draw the shape on the screen?
Once you have made the decision about representation, we can assist you in what user interface calls to make to fetch the input.
  댓글 수: 1
Minh
Minh 2022년 9월 30일
My purpose:
- point coordinates will be randomly selected.
- requires manual input of parameters such as the height and width of the square or the radius of the circle.
- the area of the triangle will be calculated from the perimeter of the triangle.

댓글을 달려면 로그인하십시오.


Sam Chak
Sam Chak 2022년 9월 30일
편집: Sam Chak 2022년 9월 30일
If you know the point coordinates of the geometry, perhaps you can explore the area() function.
x = [0 2 1.5];
y = [0 0 1];
pgon = polyshape(x, y);
plot(pgon)
axis equal
A = area(pgon) % Area
A = 1
P = perimeter(pgon) % Perimeter
P = 4.9208
  댓글 수: 1
Minh
Minh 2022년 9월 30일
@Sam Chakthanks for your contribution

댓글을 달려면 로그인하십시오.


Minh
Minh 2022년 9월 30일
#include<stdio.h>
#include<math.h>
main(){
int choice;
printf("Enter\n1 to find area of Triangle\n2 for finding area of Circle\n3 for finding area of Rectangle\n");
scanf("%d",&choice);
switch(choice) {
case 1: {
int a,b,c;
float s,area;
printf("Enter sides of triangle\n");
scanf("%d%d %d",&a,&b,&c);
s=(float)(a+b+c)/2;
area=(float)(sqrt(s*(s-a)*(s-b)*(s-c)));
printf("Area of Triangle is %f\n",area);
break;
}
case 2: {
float len,breadth,area;
printf("Enter Length and Breadth of Rectangle\n");
scanf("%f %f",&len,&breadth);
area=(float)len*breadth;
printf("Area of Rectangle is %f\n",area);
break;
}
case 3: {
float radius,area;
printf("Enter Radius of Circle\n");
scanf("%f",&radius);
area=(float)3.14159*radius*radius;
printf("Area of Circle %f\n",area);
break;

카테고리

Help CenterFile Exchange에서 Lighting, Transparency, and Shading에 대해 자세히 알아보기

태그

제품


릴리스

R2016b

Community Treasure Hunt

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

Start Hunting!

Translated by