TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   General (http://www.talkphp.com/general/)
-   -   Scratching my head a bit... (http://www.talkphp.com/general/5423-scratching-my-head-bit.html)

maeltar 05-22-2010 08:45 PM

Scratching my head a bit...
 
I know someone is going to come up with a simple solution to a problem I'm having... :'-(

I need to divide a given length (x) by a number (a) to give me a value between (y) and (z)

e.g

x = 3312
y = 181.6
z = 188.39

a = 18

Result = 184

I did that just with basic math and a bit of human brain power "fuzzy logic" and an educated guess...

Anyone got any ideas how I might go about doing this in php, the code I imagine will be easy it's just am getting lost in while's, if's and then's ....

Please help my sanity !!!!!

nefus 05-22-2010 09:20 PM

Turn your fuzzy brain logic into basic algebra. Then try a google search for doing basic math in php. If your basic code is flawed, post it here and we'll see what we see.

Village Idiot 05-23-2010 05:36 AM

Using algebra:


Those two point are your bounds, anything within them will do the job. If the ceil of the result or the floor of the result is within the bounds use that. Otherwise you will have to go with some sort of a decimal.

maeltar 05-23-2010 06:00 AM

Brilliant, thank you very much I can just loop (a) from 1 ... 30 for each (x) I knew it'd be a relatively simple answer, but sometimes when you stare at a problem you can't see the solution..

Thanks again guys :D

Village Idiot 05-23-2010 06:09 AM

Loop a? I'm not sure what you mean by that.

Out of interest, what are you trying to do with this?

maeltar 05-23-2010 06:21 AM

Ok... it's to work out how many stairs are required for a staircase...

x = Height of floor
y and z are the min and max rise allowed per stair at a given angle (UK Building Regulations)

so (a) has got to be a whole number as thats the quantity of stairs, but this is not known until it's calculated by iterating though a loop to find out what value fits...

so the way I see it I need to do something like

$a = 1

while x / $a > y
$a ++

followed by

$a = 50

while x / $a < z
$a--

Something on those lines (Obviously have simplified it for easier reading)

That should give me the max and min quantity of steps in the staircase... So need to round (a) to the nearest whole number and do a quick..

(x) / (a) to give me the exact rise of step which will be between (y) and (z)

Village Idiot 05-23-2010 05:19 PM

That seems like a good method.

Quote:

Originally Posted by maeltar (Post 30506)
Ok... it's to work out how many stairs are required for a staircase...

x = Height of floor
y and z are the min and max rise allowed per stair at a given angle (UK Building Regulations)

so (a) has got to be a whole number as thats the quantity of stairs, but this is not known until it's calculated by iterating though a loop to find out what value fits...

so the way I see it I need to do something like

$a = 1

while x / $a > y
$a ++

followed by

$a = 50

while x / $a < z
$a--

Something on those lines (Obviously have simplified it for easier reading)

That should give me the max and min quantity of steps in the staircase... So need to round (a) to the nearest whole number and do a quick..

(x) / (a) to give me the exact rise of step which will be between (y) and (z)


maeltar 05-23-2010 05:57 PM

here it is....


Seems to work well, may not be "up to standard" but it's a work in progress !!!

Probably a bit mixed up as have thrown it together but the functionality is all am bothered about right now, can pretty it up once am happy with everything...

Now am playing with GD to overlay text and dimensions on the image http://sparks.homelinux.net/astromezz/med_stringer.png

Once I have done that I want to be able to make a link so it can be downloaded as a pdf, have had a quick look at fpdf, and went back to GD... Lots to do for a bit of fun..



PHP Code:


<html>
<head><title>Astromezz Stringer Calculator</title>

<STYLE TYPE="text/css">
<!--
TD{font-family: Arial; font-size: 12pt;}
H1{font-family: Arial; font-size: 16pt;}
body{font-family: Arial; font-size: 12pt;}
spec1{font-family: Arial; font-size: 14pt;}
--->
</STYLE>
</head>
<body>

<?php

$d_height 
$_POST["d_height"];
$d_angle $_POST["d_angle"];
$j_ref $_POST["j_ref"];
$j_name $_POST["j_name"];
$j_qty $_POST["j_qty"];



# echo "<table border=\"1\" align=\"center\" size=\"100%\">";

echo "<table style=\"width: 100%; height: 199px; text-align: left; margin-left: auto; margin-right: auto;\" border=\"0\" cellpadding=\"1\" cellspacing=\"1\">";


echo 
"<tr><td style=\"white-space: nowrap; width: 25%; text-align: center;\" ><big><big><u>Job No. : " $j_ref "</big></big></u></td><td style=\"white-space: nowrap; width: 50%;\"></td>";
echo 
"<td style=\"white-space: nowrap; width: 25%; text-align: center;\"><big><big><u>Name Ref. : " $j_name "</big></big></u></td></tr>";

echo 
"    <tr align=\"center\">
      <td colspan=\"3\" rowspan=\"1\" nowrap=\"nowrap\"
 valign=\"undefined\"><big><big><big><u><i><b>STAIRCASE
DETAILS</big></big></big></u></i></b></td>
    </tr>"
;
echo 
"    <tr align=\"center\">
      <td colspan=\"3\" rowspan=\"1\" nowrap=\"nowrap\"
 valign=\"undefined\"><br><br><br><br><br><br><br><img src=\"med_stringer.png\"></td>
    </tr>


</table>"
;




echo 
"<br><br><br><br>";
echo 
"<table style=\"text-align: left; width: 33%;\" border=\"1\" cellpadding=\"1\" cellspacing=\"1\">";


function 
calc_steps($y,$z,$x,$w)
{

#  $y = Min step Height
#  $z = Max Step Height
#  $x = Deck (floor) height
#  $w = Stringer (stair) length
#
#


$aa 1;    #### Increment steps 1 ...  


while ( ($x $aa) > $y )
    {
    
$aa++;
    }

echo 
"<tr><td>Rises in flight :</td><td>" . ($aa 1) . "</td>";

echo 
"<tr><td>Tread Rise Height :</td><td>" round(($x / ($aa 1)),2) . "</td>";

echo 
"<tr><td>Going Along Flat : </td><td>" round(($w / ($aa 1)),1) . "</td>";


if ( (
$x / ($aa 1)) > $z )
        {
        echo 
"<br><b>Rise Height greater than max allowed !!! </b><i>("$z "mm)</i>";
        echo 
"<br> Using one extra step ("$aa .") would give a Rise height of : ";
        echo 
round($x / ($aa),2) . "mm";
    echo 
"<br> But that is below the Minimum Rise height of " $y "mm";
        }



}



switch (
$d_angle){
    case 
"35";
        
$str_len $d_height 1.743;
        
$floor_len $d_height 1.428;
        echo 
"<tr><td style=\"white-space: nowrap; width: 50%;\">Deck Height : </td><td style=\"white-space: nowrap; width: 50%;\">" $d_height "</td>";
        echo 
"<tr><td>Stringer Length : </td><td>" round($str_len,1) . "</td>";
        echo 
"<tr><td>Floor Length : </td><td>" round($floor_len,1) . "</td>";
        echo 
"<tr><td>Stair Angle : </td><td>" $d_angle ?>&deg<?php echo "</td>";
        
calc_steps(175,181.59,$d_height,$str_len);
        break;
    case 
"36";
        
$str_len $d_height 1.701;
                
$floor_len $d_height 1.376;
                echo 
"<tr><td style=\"white-space: nowrap; width: 50%;\">Deck Height : </td><td style=\"white-space: nowrap; width: 50%;\">" $d_height "</td>";
                echo 
"<tr><td>Stringer Length : </td><td>" round($str_len,1) . "</td>";
                echo 
"<tr><td>Floor Length : </td><td>" round($floor_len,1) . "</td>";
                echo 
"<tr><td>Stair Angle : </td><td>" $d_angle ?>&deg<?php echo "</td>";
        
calc_steps(181.6,188.39,$d_height,$str_len);
        break;
    case 
"37";
        
$str_len $d_height 1.6617;
        
$floor_len $d_height 1.327;
                echo 
"<tr><td style=\"white-space: nowrap; width: 50%;\">Deck Height : </td><td style=\"white-space: nowrap; width: 50%;\">" $d_height "</td>";
                echo 
"<tr><td>Stringer Length : </td><td>" round($str_len,1) . "</td>";
                echo 
"<tr><td>Floor Length : </td><td>" round($floor_len,1) . "</td>";
                echo 
"<tr><td>Stair Angle : </td><td>" $d_angle ?>&deg<?php echo "</td>";
        
calc_steps(188.4,190,$d_height,$str_len);
        break;
}  
## end case



?>
</table>

<big><big><big><u><i><b>Qty of Stringer Pairs Required : <?php echo $j_qty?></big></big></big></u></i></b>


</body>
</html>



All times are GMT. The time now is 07:59 PM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0