Search Here

Sunday, July 8, 2018

Toph - Simple Pyramid [ Tutorial + Solution ]

=>Try Yourself First. For help Scroll Down .

In the last ProgKriya contest there was a problem named Simple Pyramid. Problem seems very interesting to me although I could not able to solve it within contest time. Anyway, I am sharing my approach.

Here is the problem link: https://toph.co/p/simple-pyramid

Problem Clearance:

Given a Pyramid with N 3D vertices in counter-clockwise direction and height from ground which is H. The counter - clockwise direction simply implies that from the starting coordinate you have to move to the left. See the image below if you are not clear about counter - clockwise direction -


What you have to find is the Volume of the Pyramid and the slanted surface area. The slanted surface area is the surface area excluding base area. Watch the image below for better clarification -

Volume: is the amount of space that occupies by the pyramid. In simple words if we put the pyramid into the ground then what amount of component can stay within it. Here the first picture illustrated the volume of the pyramid.

Slanted surface area: If we split every surface of the pyramid then the area we can get after excluding the base area is slanted surface area. Here the second picture shows the complete surface area. But if we exclude the base area (the blue portion) then we will get the slanted surface area.

Hope the basics area cleared by now.

Procedure:

To find out the Volume: The volume of a pyramid is = 1/3*B*H  where B is the area of the base and H is the height from the ground. The value of H is given. To find out the Base Area B we will use Matrix Determinant form. If you are given a polygon with N coordinates then the area of the polygon in Matrix Determinant form can be show as - 
Here the bold bars ( | ... | ) denotes the absolute value. So using this formula we can figure the area of base ( the blue area ). Then, putting this value in equation 1/3*B*H we can figure out the volume.


To find out Slanted Surface Area: From the figure of surface area given above, we can easily understand that the slated surface area the red region. But how can we find this out. Look closely , two adjacent point and the apex A forms a triangle. That means if you find out the area of N triangles formed with the A and any two adjacent coordinate in counter-clockwise direction and then sum it up you will be able to find out the slanted surface area. Here for each of the coordinate there is no Z-axis but for apex coordinate A there is a Z-axis. For any triangle with 3D coordinates area can be figure out as follows - 



Using the following calculation we can calculate the area of a triangle formed of 3D coordinates. Now for any two adjacent coordinate and apex find out the area in counter clockwise direction and sum it up. That will be the slanted surface area.

Note: The area of a triangle can also figure out with Heron's Formula.

=================================== Hope you Solved by Now ======================================

Source Code:  https://gist.github.com/ssavi-ict/2674ac16617820bde12eb01b2a88a6e0

=>Leave a comment for any kinds of Hugs and / or Bugs. Thank you .

No comments:

Post a Comment