September 22nd, 2013, 10:23 PM

Calculating area of rectangle or circle procedure based method
Hi
I have never done it. Would you please give me some tips on how to do it in procedure based method and NOT oop.
Thanks
September 23rd, 2013, 02:50 AM

How to calculate the area of a rectangle or a circle? I sure hope it's something more complicated than that.
Details. You've been here long enough to know that we need them.
September 23rd, 2013, 03:36 AM

Originally Posted by requinix
I sure hope it's something more complicated than that.
didn't you go to school?
Maybe you've forgotten that PHP can do basic maths just by writing +,,* and / ?
Maybe you don't know how to get the value of pi?
PHP has a built in function which returns the value of pi (to some approximation, limited by variable length)...it's called [PHPNET="pi"]pi()[/PHPNET] for some reason.
There's also the constant, M_PI, and a few derivatives should you need them
Then, just remember that in PHP * means multiply and / means divide,
eg
$area_of_rectangle = $length * $width;
and
$area_of_circle = pi() * $radius * $radius;
or
$area_of_circle = pi() * pow($radius,2);
Last edited by Northie; September 23rd, 2013 at 03:38 AM.
September 23rd, 2013, 05:12 AM

I am gonna blame it on my English.
A 6 year old can do this.
September 23rd, 2013, 12:36 PM

Originally Posted by English Breakfast Tea
I am gonna blame it on my English.
A 6 year old can do this.
So what was the original problem?
September 23rd, 2013, 08:23 PM

Originally Posted by Northie
So what was the original problem?
The upload dynamic size for 3d images (cone, pyramid and cylender) and need to calculate the volume depending on the size and shape.
September 24th, 2013, 02:49 AM

Using procedural programming, you'd probably have one function for each shape.
Like for example
PHP Code:
<?php
function volume_cone($radius, $height) {
$base_area = M_PI * $radius * $radius;
return (1/3) * $base_area * $height;
}
You might also write down the calculations directly if you only need them once. But personally, I'd hide lowlevel math like this from the actual code.