Charles Pegge
03-02-2010, 19:29
This is part of a real project to design a small rotunda greenhouse. It calculates the shape of the roof and wall panels including mitre and bevel angles for the frame. The output is only a set of figures at this stage, and in the absence of a modelling device scissors cardboard and tape give a fair representation of the design.
Before this program gets too complicated, I wanted to use it to show off some of the latest Oxygen features, which includes some C like syntax. The aim is to produce very clear and highly maintainable code, so it can be extended to produce further variations in design and more detailed outputs such as materials and costs.
In particular, note the Report method which uses 2 inner functions: single liners to help format the output values. As inner functions these are completely encapsulated inside the method and invisible to the rest of the program.
Latest Oxygen with a few adjustments as usual :)
http://community.thinbasic.com/index.php?topic=2517
'----------------------------------------
'Polyhedral GreenHouse
'========================================
'16:18 03/02/2010
uses "oxygen","file"
dim src as string
src ="
basic
/*
ROOF PANEL
/\ apex
/ \
/ \
-------------- truncation
/ \
/ main \
/ \
..............
\ / /\
\ tail / / \
\ / / \
\ / / \
\ / / head \
\ / / \
\/ / \
------------------------
| main | shoulder
| |
SIDE PANEL | |
| |
| |
| |
| |
| |
| |
--------------
*/
class greenhouse
protected double
a,b,n,r,
w1,w2,w3,h1,h2,h3,
fr,ta,ra,rm,sh,s1,s2,v1,sc,ma,
sina,cosa,tana,sinb,cosb,tanb,
rptw,rptm,rtam,rsdm,rptr,sdtm,sdsm
'----------------------------------------------------------
method input(double scale, double sides, double RoofSlope )
'==========================================================
'INPUTS
sc=scale 'SCALE
n=sides 'NUMBER OF SIDES
a=pi/n 'MAIN ANGLE
b=rad(RoofSlope) 'ROOF PANEL SLOPE
rptw=0.2*sc 'ROOF PANEL TRUNCATION WIDTH
end method
'-----------------
method calculate()
'=================
'TRIGO PROPORTIONS
cosa=cos a
sina=sin a
tana=tan a
sinb=sin b
cosb=cos b
tanb=tan b
'MAIN CALCS
r=sc/cos(a) 'CORNER RADIUS
fr=r*cosa 'FACE RADIUS
w1=r*sina 'SIDE PANEL W1
w2=w1*cosa 'ROOF PANEL W2
h1=w1*sina/cosb 'ROOF PANEL TAIL
h2=r*cosa/cosb 'ROOF PANEL MAIN
v1=h1*sinb 'SIDE PANEL PEAK
ta=atn(h1/w2) 'TAIL ANGLE
ma=atn( tana/sin(ta) )/2 'TAIL BEVEL
ra=asin(sina*cosa*cosb) 'ROOF ANGLE
rptr=h2-rptw/tan(ra) 'ROOF PANEL TRUNCATED
rm=atn(tana*sinb*cos(ra) ) 'ROOF BEVEL
sh=sc*2-v1 'SIDE PANEL SHOULDER HEIGHT
rptm=atn(h2/w2)*.5 'ROOF PANEL TOP MITRE
rtam=ta 'ROOF PANEL TAIL MITRE
rsdm=.5*(pi-atn(h2/w2)-ta) 'ROOF PANEL SIDE MITRE
sdtm=atn(v1/w1) 'SIDE PANEL TIP MITRE
sdsm=pi*.25-sdtm*.5 'SIDE PANEL SHOULDER MITRE
end method
'OUTPUT
'--------------
method report()
'==============
function degs(double d) as string= left(str(deg(d)),5) chr(9)
function vals(double d) as string = left(str(d),5) chr(9)
print `
Polyhedral GreenHouse Measurements:
` vals(this.sc) `scaling
` vals(r) `Corner radius
` vals(fr) `Face radius
` vals(n) `number of sides
` degs(b) `roof slope
--------------------------------------
` vals(w2) `roof panel half width
` vals(h1) `roof panel tail
` vals(h2) `roof panel main
` vals(rptw) `roof panel truncation width
` vals(rptr) `roof panel truncated
--------------------------------------
` degs(ta) `roof tail angle
` degs(ra) `roof panel apex angle
--------------------------------------
` degs(rptm) `roof panel top mitre
` degs(rsdm) `roof panel side mitre
` degs(rtam) `roof panel tail mitre
` degs(b ) `roof panel top bevels (top opening)
` degs(rm) `roof panel side bevels
` degs(ma) `roof panel tail bevels
--------------------------------------
` vals(w1) `side panel half width
` vals(sh) `side panel shoulder
` vals(v1) `side panel head
` degs(sdtm) `side panel tip mitre
` degs(sdsm) `side panel shoulder mitre
` vals(45) `side panel base mitre
` degs(a ) `side panel side bevels
` degs(ma) `side panel apex bevels
`
end method
end class
'----
'MAIN
'====
greenhouse g
g.input 1,6,45 '(double scale, double sides, double RoofSlope )
g.calculate
g.report
"
'file_save ( "t.txt", o2_prep src )
'msgbox 0, o2_prep src
o2_asmo src
if len(o2_error) then
msgbox 0, o2_error : stop
end if
o2_exec
Latest Version Attached below
Featuring inner class for processing panel frame struts.
Before this program gets too complicated, I wanted to use it to show off some of the latest Oxygen features, which includes some C like syntax. The aim is to produce very clear and highly maintainable code, so it can be extended to produce further variations in design and more detailed outputs such as materials and costs.
In particular, note the Report method which uses 2 inner functions: single liners to help format the output values. As inner functions these are completely encapsulated inside the method and invisible to the rest of the program.
Latest Oxygen with a few adjustments as usual :)
http://community.thinbasic.com/index.php?topic=2517
'----------------------------------------
'Polyhedral GreenHouse
'========================================
'16:18 03/02/2010
uses "oxygen","file"
dim src as string
src ="
basic
/*
ROOF PANEL
/\ apex
/ \
/ \
-------------- truncation
/ \
/ main \
/ \
..............
\ / /\
\ tail / / \
\ / / \
\ / / \
\ / / head \
\ / / \
\/ / \
------------------------
| main | shoulder
| |
SIDE PANEL | |
| |
| |
| |
| |
| |
| |
--------------
*/
class greenhouse
protected double
a,b,n,r,
w1,w2,w3,h1,h2,h3,
fr,ta,ra,rm,sh,s1,s2,v1,sc,ma,
sina,cosa,tana,sinb,cosb,tanb,
rptw,rptm,rtam,rsdm,rptr,sdtm,sdsm
'----------------------------------------------------------
method input(double scale, double sides, double RoofSlope )
'==========================================================
'INPUTS
sc=scale 'SCALE
n=sides 'NUMBER OF SIDES
a=pi/n 'MAIN ANGLE
b=rad(RoofSlope) 'ROOF PANEL SLOPE
rptw=0.2*sc 'ROOF PANEL TRUNCATION WIDTH
end method
'-----------------
method calculate()
'=================
'TRIGO PROPORTIONS
cosa=cos a
sina=sin a
tana=tan a
sinb=sin b
cosb=cos b
tanb=tan b
'MAIN CALCS
r=sc/cos(a) 'CORNER RADIUS
fr=r*cosa 'FACE RADIUS
w1=r*sina 'SIDE PANEL W1
w2=w1*cosa 'ROOF PANEL W2
h1=w1*sina/cosb 'ROOF PANEL TAIL
h2=r*cosa/cosb 'ROOF PANEL MAIN
v1=h1*sinb 'SIDE PANEL PEAK
ta=atn(h1/w2) 'TAIL ANGLE
ma=atn( tana/sin(ta) )/2 'TAIL BEVEL
ra=asin(sina*cosa*cosb) 'ROOF ANGLE
rptr=h2-rptw/tan(ra) 'ROOF PANEL TRUNCATED
rm=atn(tana*sinb*cos(ra) ) 'ROOF BEVEL
sh=sc*2-v1 'SIDE PANEL SHOULDER HEIGHT
rptm=atn(h2/w2)*.5 'ROOF PANEL TOP MITRE
rtam=ta 'ROOF PANEL TAIL MITRE
rsdm=.5*(pi-atn(h2/w2)-ta) 'ROOF PANEL SIDE MITRE
sdtm=atn(v1/w1) 'SIDE PANEL TIP MITRE
sdsm=pi*.25-sdtm*.5 'SIDE PANEL SHOULDER MITRE
end method
'OUTPUT
'--------------
method report()
'==============
function degs(double d) as string= left(str(deg(d)),5) chr(9)
function vals(double d) as string = left(str(d),5) chr(9)
print `
Polyhedral GreenHouse Measurements:
` vals(this.sc) `scaling
` vals(r) `Corner radius
` vals(fr) `Face radius
` vals(n) `number of sides
` degs(b) `roof slope
--------------------------------------
` vals(w2) `roof panel half width
` vals(h1) `roof panel tail
` vals(h2) `roof panel main
` vals(rptw) `roof panel truncation width
` vals(rptr) `roof panel truncated
--------------------------------------
` degs(ta) `roof tail angle
` degs(ra) `roof panel apex angle
--------------------------------------
` degs(rptm) `roof panel top mitre
` degs(rsdm) `roof panel side mitre
` degs(rtam) `roof panel tail mitre
` degs(b ) `roof panel top bevels (top opening)
` degs(rm) `roof panel side bevels
` degs(ma) `roof panel tail bevels
--------------------------------------
` vals(w1) `side panel half width
` vals(sh) `side panel shoulder
` vals(v1) `side panel head
` degs(sdtm) `side panel tip mitre
` degs(sdsm) `side panel shoulder mitre
` vals(45) `side panel base mitre
` degs(a ) `side panel side bevels
` degs(ma) `side panel apex bevels
`
end method
end class
'----
'MAIN
'====
greenhouse g
g.input 1,6,45 '(double scale, double sides, double RoofSlope )
g.calculate
g.report
"
'file_save ( "t.txt", o2_prep src )
'msgbox 0, o2_prep src
o2_asmo src
if len(o2_error) then
msgbox 0, o2_error : stop
end if
o2_exec
Latest Version Attached below
Featuring inner class for processing panel frame struts.