- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Find the Surface area of a 3D figure in Python
Suppose we have a N*M matrix A, this is the representation of 3D figure. The height of the building at point (i, j) is A[i][j]. We have to find the surface area of the figure.
So, if the input is like N = 3, M = 3, A = [[1, 4, 5],[3, 3, 4],[1, 3, 5]], then the output will be 72.
To solve this, we will follow these steps −
res := 0
for i in range 0 to N, do
for j in range 0 to M, do
up_side := 0
left_side := 0
if i > 0, then
up_side := array[i - 1, j]
if j > 0, then
left_side := array[i, j - 1]
res := res + |array[i][j] - up_side| + |array[i][j] - left_side|
if i is same as N - 1, then
res := res + array[i, j]
if j is same as M - 1, then
res := res + array[i, j]
res := res + N * M * 2
return res
Example
Let us see the following implementation to get better understanding −
M = 3 N = 3 def get_surface_area(array): res = 0 for i in range(N): for j in range(M): up_side = 0 left_side = 0 if (i > 0): up_side = array[i - 1][j] if (j > 0): left_side = array[i][j - 1] res += abs(array[i][j] - up_side)+abs(array[i][j] - left_side) if (i == N - 1): res += array[i][j] if (j == M - 1): res += array[i][j] res += N * M * 2 return res array = [[1, 4, 5],[3, 3, 4],[1, 3, 5]] print(get_surface_area(array))
Input
[[1, 4, 5],[3, 3, 4],[1, 3, 5]]
Output
72
- Related Articles
- Surface Area of 3D Shapes in Python
- Find the ratio of the total surface area and lateral surface area of a cube.
- Find the lateral surface area and total surface area of a cube of edge $10 cm$.
- How to obtain 3D colored surface via Python?
- A solid cylinder has a total surface area of $231 cm^2$. Its curved surface area is $frac{2}{3}$ of the total surface area. Find the volume of the cylinder.
- How To Find the Surface Area of Hemisphere in Java?
- Plotting a 3D surface from a list of tuples in matplotlib?
- Find the area of the green figure:"\n
- A right circular cylinder just encloses a sphere of radius ( r ) (see in figure below). Find(i) surface area of the sphere,(ii) curved surface area of the cylinder,(iii) ratio of the areas obtained in (i) and (ii)."\n
- A solid cylinder has total surface area of $462 cm^2$. Its curved surface area is one-third of its total surface area. Find the radius and height of the cylinder.
- Plot a 3D surface from {x,y,z}-scatter data in Python Matplotlib
- Find the area of the shaded region in figure."\n
- Projection Area of 3D Shapes
- Write the formula for the curved surface area and total surface area of the frustum of a cone.
- The surface area of a cube is 384 cm2. Find its volume.
