Calculate the area of geometry

11 views (last 30 days)
Minh on 30 Sep 2022
Answered: Hala on 18 Oct 2022
I have a difficult problem and I need help, "Write a function to calculate the area and perimeter of shapes: triangle, rectangle, circle?"
Minh on 30 Sep 2022
@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.

Sign in to comment.

Answers (4)

Walter Roberson
Walter Roberson on 30 Sep 2022
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 ? 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 Comment
Minh on 30 Sep 2022
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.

Sign in to comment.

Sam Chak
Sam Chak on 30 Sep 2022
Edited: Sam Chak on 30 Sep 2022
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);
axis equal
A = area(pgon) % Area
A = 1
P = perimeter(pgon) % Perimeter
P = 4.9208
  1 Comment
Minh on 30 Sep 2022
@Sam Chakthanks for your contribution

Sign in to comment.

Minh on 30 Sep 2022
int choice;
printf("Enter\n1 to find area of Triangle\n2 for finding area of Circle\n3 for finding area of Rectangle\n");
switch(choice) {
case 1: {
int a,b,c;
float s,area;
printf("Enter sides of triangle\n");
scanf("%d%d %d",&a,&b,&c);
printf("Area of Triangle is %f\n",area);
case 2: {
float len,breadth,area;
printf("Enter Length and Breadth of Rectangle\n");
scanf("%f %f",&len,&breadth);
printf("Area of Rectangle is %f\n",area);
case 3: {
float radius,area;
printf("Enter Radius of Circle\n");
printf("Area of Circle %f\n",area);

Hala on 18 Oct 2022
explaining to them that it can calculate the area of right-angled triangle, with two inputs (width & height). The program displays the output (the area of the triangle) to the user in the command window. Part 2





Community Treasure Hunt

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

Start Hunting!

Translated by