TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 05-22-2010, 08:45 PM   #1 (permalink)
The Acquainted
 
Join Date: Nov 2009
Location: nr Stratford-Upon-Avon
Posts: 137
Thanks: 3
maeltar is on a distinguished road
Default 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 !!!!!
__________________
Thanks... Simon

Sex, Drugs & Linux Rules
Send a message via MSN to maeltar
maeltar is offline  
Reply With Quote
Old 05-22-2010, 09:20 PM   #2 (permalink)
The Contributor
 
nefus's Avatar
 
Join Date: Nov 2007
Location: Nashville, TN
Posts: 66
Thanks: 20
nefus is on a distinguished road
Default

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.
__________________
I am not a programmer, nor do I play one on tv.
nefus is offline  
Reply With Quote
Old 05-23-2010, 05:36 AM   #3 (permalink)
Wizard
Top Contributor 
 
Village Idiot's Avatar
 
Join Date: Sep 2007
Posts: 1,299
Thanks: 17
Village Idiot is on a distinguished road
Default

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.
__________________

Village Idiot is offline  
Reply With Quote
The Following User Says Thank You to Village Idiot For This Useful Post:
maeltar (05-23-2010)
Old 05-23-2010, 06:00 AM   #4 (permalink)
The Acquainted
 
Join Date: Nov 2009
Location: nr Stratford-Upon-Avon
Posts: 137
Thanks: 3
maeltar is on a distinguished road
Default

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
__________________
Thanks... Simon

Sex, Drugs & Linux Rules
Send a message via MSN to maeltar
maeltar is offline  
Reply With Quote
Old 05-23-2010, 06:09 AM   #5 (permalink)
Wizard
Top Contributor 
 
Village Idiot's Avatar
 
Join Date: Sep 2007
Posts: 1,299
Thanks: 17
Village Idiot is on a distinguished road
Default

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

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

Village Idiot is offline  
Reply With Quote
Old 05-23-2010, 06:21 AM   #6 (permalink)
The Acquainted
 
Join Date: Nov 2009
Location: nr Stratford-Upon-Avon
Posts: 137
Thanks: 3
maeltar is on a distinguished road
Default

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)
__________________
Thanks... Simon

Sex, Drugs & Linux Rules
Send a message via MSN to maeltar
maeltar is offline  
Reply With Quote
Old 05-23-2010, 05:19 PM   #7 (permalink)
Wizard
Top Contributor 
 
Village Idiot's Avatar
 
Join Date: Sep 2007
Posts: 1,299
Thanks: 17
Village Idiot is on a distinguished road
Default

That seems like a good method.

Quote:
Originally Posted by maeltar View Post
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 is offline  
Reply With Quote
Old 05-23-2010, 05:57 PM   #8 (permalink)
The Acquainted
 
Join Date: Nov 2009
Location: nr Stratford-Upon-Avon
Posts: 137
Thanks: 3
maeltar is on a distinguished road
Default

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>
__________________
Thanks... Simon

Sex, Drugs & Linux Rules
Send a message via MSN to maeltar
maeltar is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
While loop is over my head Dave Absolute Beginners 6 09-02-2009 02:31 AM


All times are GMT. The time now is 10:00 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design