richeyrose
Hiya,
Since there's not an arctan function in the prefab language calculating angles dynamically for staircase railings, roofs etc. had me a bit stumped. I spent a few hours researching this morning and found the below methods for approximating arctan which will allow you to calculate the slope of a staircase / roof in radians from the rise and run. I figured others would find this useful.

"
This is for x in [0, Infinity). When x is negative just use -atan_approx(-x). 

Second order: 

atan_approx(x) = (Pi/2)*(b*x + x*x)/(1 + 2*b*x + x*x) where b = 0.596227, with a maximum approximation error of 0.1620º 

Third order: 

atan_approx(x) = (Pi/2)*(c*x + x*x + x*x*x)/(1 + (c+1)*x + (c+1)x*x + x*x*x) where c = (1 + sqrt(17))/8 and the maximum approximation error is 0.00811º 
"

from here: https://www.embedded.com/design/other/4216719/Performing-efficient-arctangent-approximation

Haven't put this into practise yet but it should work.
0 0
richeyrose
A very quick and dirty implementation:

step {
scale [100%, riser, 100%]
instance "wall_1m"
}

stairstep : width < 0.1 {}

stairstep {
module step
module {
scale [100% - tread, 100%, 100%]
move [0, riser, 0]
module stairstep
}
}

railingRight {
center xy
move [-2.5, 5, 0]
scale [H, 1, 1]
rotate z deg
instance "wall_1m"
}

railingLeft {
center xy
move [-2.5, 5, 100%-m]
scale [H, 1, 1]
rotate z deg
instance "wall_1m"
}

main {
module railingRight
module railingLeft
const m 1
const riser 1
const c (height/width)
const Osq pow(height, 2)
const Asq pow(width, 2)
const H sqrt(Osq+Asq) //get the length of the hypotenuse
const pi 3.141592
const b 0.596227
const rad (pi/2)*(b*c + c*c)/(1+2*b*c+c*c) //estimate arctan - returns radians
const deg rad*180/pi
const tread (width * riser) / height
module {

material Stairs
module stairstep
}
}
0 0