![]() |
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 !!!!! |
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.
|
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. |
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 |
Loop a? I'm not sure what you mean by that.
Out of interest, what are you trying to do with this? |
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) |
That seems like a good method.
Quote:
|
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:
|
| 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