Crown.php source code
Contents of file
yurtparts/Crown.php
1
<?php
2 // Software released under the General Public License (version 2 or later), available at
3 // http://www.gnu.org/copyleft/gpl.html
4 //********************************************************************************
5 /**
6 Calculs liés à la couronnne
7
8 @version 1.0
9 @license GPL
10 @author Thierry Graff
11 @weblink http://www.tig12.net
12 @php PHP5
13 @history 2007.05.24, 04h03 : Creation
14 @history 2007.06.12 : transformation to a class
15 ****************************************************************************************/
16 require_once(dirname(dirname(__FILE__)) . '/YurtPart.php');
17
18 class Crown extends YurtPart{
19
20 /** Variable used to exchange data between main() and plank() */
21 private $gamma_deg;
22
23 /**
24 @param $params Can be 'main' or 'plank'
25 'main' returns the html code of a table with crown's main data.
26 'plank' returns an image with the measures of the plank.
27 */
28 public function toHtml($params=''){
29 switch($params){
30 case 'main' : return $this->main();
31 case 'plank' : return $this->plank();
32 default : throw new Exception('Crown.toHtml() called with wrong parameter $params');
33 }
34 }// end toHtml
35
36
37 /** Generates a table withe crown's main data */
38 private function main(){
39 // Variables importees
40 $D = $this->yurt->getConfig('general', 'D'); // Diamètre de la yourte, en m
41 $alpha = $this->yurt->getConfig('general', 'alpha'); // radians
42 $np = $this->yurt->getConfig('general', 'np'); // nombre de perches fichées dans la couronne
43 //
44 // Valeurs à fixer à cette étape
45 $lpc = $this->yurt->getConfig('crown', 'lpc'); // longueur de perche dans couronne, en m
46 $dpc = $this->yurt->getConfig('crown', 'dpc'); // diametre perche dans couronne, en m
47 //
48 $dc = $this->yurt->getConfig('general', 'dc'); // diamètre extérieur de la couronne, en m
49 $hc = $this->yurt->getConfig('crown', 'hc'); // épaisseur horizontale de la couronne, en m
50 $vc = $this->yurt->getConfig('crown', 'vc'); // épaisseur verticale de la couronne, en m
51 // planches
52 $wpc = $this->yurt->getConfig('crown', 'wpc'); // largeur des planches, en m
53 $epc = $this->yurt->getConfig('crown', 'epc'); // épaisseur des planches, en m
54 // detail
55 $AM = $this->yurt->getConfig('crown', 'AM'); // décalage vertical perche, en m
56 // cout
57 $cam = $this->yurt->getConfig('crown', 'cam'); // cout au mètre linéaire de planches, en euros
58
59 // ************* calculs
60 // generalites
61 $R = $D / 2;
62 $rc = $dc / 2;
63 $pc = 2 * M_PI * $rc;
64 // rayon interne
65 $dci = $dc - 2*$hc;
66 $rci = $dci / 2;
67 // repartition des trous
68 $delta = (2 * M_PI * $rc - $np * $dpc) / $np;
69 // planches
70 $gamma1 = acos(($rc - $wpc) / ($rc - $hc)); // radians
71 $gamma1_deg = 180 * $gamma1 / M_PI;
72 $npc1 = ceil(360/(2*$gamma1_deg));
73 $gamma_deg = 180 / $npc1;
74 $gamma = M_PI * $gamma_deg / 180;
75 $nepc = $hc / $epc;
76 $npc = $npc1 * $nepc;
77 $lbpc = 2 * $rc * sin($gamma);
78 $ltpc = $lbpc * $npc;
79 // detail
80 $PM = $dpc / cos($alpha);
81 $H1N = $lpc + ($AM + $dpc) * sin($alpha);
82 $AI = $AM + $dpc / (2 * cos($alpha));
83 $IJ = $lpc + $dpc / 2 *tan($alpha);
84 $PD = $vc - $PM - $AM;
85 $OH3 = $PD - $lpc * sin($alpha);
86 $AH7 = $dpc * sin($alpha) + $lpc * cos($alpha);
87 // cout
88 $coutPlanche = $cam * $lbpc;
89 $coutTotal = $cam * $ltpc;
90
91 // Affichage des résultats
92 $res = '';
93 $res .= "<table>\n";
94 $res .= "<tr><th colspan='2'><b>Variables importées</b></th></tr>\n";
95 $res .= "<tr><td>Diamètre perches dans couronne</td><td><b>dpc = " . round(self::m2cm($dpc), 2) . " cm</b></td></tr>\n";
96 $res .= "<tr><td>Longueur de perche dans couronne</td><td><b>lpc = " . round(self::m2cm($lpc), 2) . " cm</b></td></tr>\n";
97 $res .= "<tr><td>Angle du toit</td><td><b>α = " . round($alpha*180/M_PI, 2) . " °</b></td></tr>\n";
98 //
99 $res .= "<tr><th colspan='2'>Couronne</th></tr>\n";
100 $res .= "<tr><td>Diamètre extérieur</td><td><b>dc = dce = " . round($dc) . " m</b></td></tr>\n";
101 $res .= "<tr><td>Rayon extérieur</td><td><b>rc = rce = " . round($rc) . " m</b></td></tr>\n";
102 $res .= "<tr><td>Périmètre extérieur</td>
103 <td><b>pce = " . round($pc, 2) . " m</b>
104 </tr>\n";
105 $res .= "<tr><td>Diamètre intérieur</td><td><b>dci = " . round($dci) . " m</b></td></tr>\n";
106 $res .= "<tr><td>Rayon intérieur</td><td><b>rci = " . round($rci) . " m</b></td></tr>\n";
107 $res .= "<tr><td>Epaisseur horizontale</td><td><b>hc = " . round(self::m2cm($hc)) . " cm</b></td></tr>\n";
108 $res .= "<tr><td>Epaisseur verticale</td><td><b>vc = " . round(self::m2cm($vc)) . " cm</b></td></tr>\n";
109 //
110 $res .= "<tr><th colspan='2'>Planches</th></tr>\n";
111 $res .= "<tr><td>Largeur des planches</td><td><b>wpc = " . round(self::m2cm($wpc)) . " cm</b></td></tr>\n";
112 $res .= "<tr><td>Epaissseur des planches</td><td><b>epc = " . round(self::m2cm($epc)) . " cm</b></td></tr>\n";
113 $res .= "<tr><td>Nombre d'étages de planches</td><td><b>nepc = " . $nepc . "</b></td></tr>\n";
114 $res .= "<tr><td>Angle intermédiaire</td><td><b>γ<sub>1</sub> = " . round($gamma1_deg) . " °</b></td></tr>\n";
115 $res .= "<tr><td>Angle retenu</td><td><b>γ = " . round($gamma_deg) . " °</b></td></tr>\n";
116 $res .= "<tr><td>Nombre de bouts de planche par étage</td><td><b>npc1 = " . $npc1 . "</b></td></tr>\n";
117 $res .= "<tr><td>Nombre total de bouts de planche</td><td><b>npc = " . $npc . "</b></td></tr>\n";
118 $res .= "<tr><td>Longueur d'un bout de planche</td><td><b>lbpc = " . round(self::m2cm($lbpc)) . " cm</b></td></tr>\n";
119 $res .= "<tr><td>Longueur totale de planche nécessaire</td><td><b>ltpc = " . round($ltpc) . " m</b></td></tr>\n";
120 $res .= "<tr><td>Coût au mètre de planche</td><td><b>cam = " . $cam . " euros</b></td></tr>\n";
121 //
122 $res .= "<tr><th colspan='2'>Perches dans la couronne</th></tr>\n";
123 $res .= "<tr><td>Nombre de perches</td><td><b>np = $np</b></td></tr>\n";
124 $res .= "<tr><td>Diamètre extérieur couronne</td><td><b>dc = dce = " . round($dc) . " m</b></td></tr>\n";
125 $res .= "<tr><td>Diamètre intérieur couronne</td><td><b>dci = " . round($dci) . " m</b></td></tr>\n";
126 $res .= "<tr><td>Périmètre extérieur couronne</td>
127 <td><b>pce = " . round($pc, 2) . " m</b>
128 <br/><b>pc / 360 = " . round(self::m2cm($pc/360), 2) . " cm</b>
129 <br/><b>pc / np = " . round(self::m2cm($pc/$np), 2) . " cm</b></td>
130 </tr>\n";
131 $res .= "<tr><td>Diamètre perche dans couronne</td><td><b>dpc = " . round(self::m2cm($dpc)) . " cm</b></td></tr>\n";
132 $res .= "<tr><td>Espace entre deux trous</td><td><b>dit = " . round(self::m2cm($delta)) . " cm</b></td></tr>\n";
133 //
134 $res .= "<tr><th colspan='2'>Détails d'un trou de perche</th></tr>\n";
135 $res .= "<tr><td>Décalage - choix effectué</td><td><b>AM = " . round(self::m2cm($AM)) . " cm</b></td></tr>\n";
136 $res .= "<tr><td>Longueur perche à tailler au bon diamètre</td><td><b>H<sub>1</sub>N = lpc2 = " . round(self::m2cm($H1N)) . " cm</b></td></tr>\n";
137 $res .= "<tr><td>Position du trou</td><td><b>AI = " . round(self::m2cm($AI)) . " cm</b></td></tr>\n";
138 $res .= "<tr><td>Profondeur du trou</td><td><b>IJ = " . round(self::m2cm($IJ)) . " cm</b></td></tr>\n";
139 $res .= "<tr><td>Pour l'isolant</td><td><b>PD = " . round(self::m2cm($PD)) . " cm</b></td></tr>\n";
140 $res .= "<tr><td>Pour voir solidité</td><td><b>OH<sub>3</sub> = " . round(self::m2cm($OH3)) . " cm</b></td></tr>\n";
141 $res .= "<tr><td>Profondeur du trou</td><td><b>AH<sub>7</sub> = " . round(self::m2cm($AH7)) . " cm</b></td></tr>\n";
142 //
143 $res .= "<tr><th colspan='2'>Prix</th></tr>\n";
144 $res .= "<tr><td>Coût planches au mètre</td><td><b>cam = " . round($cam, 2) . " euros</b></td></tr>\n";
145 $res .= "<tr><td>Coût d'un élément</td><td><b>coutPlanche = " . round($coutPlanche, 2) . " euros</b></td></tr>\n";
146 $res .= "<tr><td>Coût total</td><td><b>coutTotal = " . round($coutTotal, 2) . " euros</b></td></tr>\n";
147 $res.= "</table>\n";
148
149 return $res;
150 }// end main
151
152 /** Generates an image with the measures to cut a round piece of wood */
153 private function plank(){
154 //echo "<pre>"; print_r($this->data); echo "</pre>";
155 // Valeurs importées, à fixer par l'utilisateur
156 $dc = $this->yurt->getConfig('general', 'dc'); // diamètre extérieur de la couronne, en m
157 $hc = $this->yurt->getConfig('crown', 'hc'); // épaisseur horizontale de la couronne, en m
158 $gamma_deg = $this->gamma_deg;
159 $step = $this->yurt->getConfig('crown', 'step'); // pas en degrés
160 $lbpc = $this->yurt->getConfig('crown', 'lbpc'); // longueur d'un bout de planche, en cm
161 $wpc = $this->yurt->getConfig('crown', 'wpc'); // largeur d'un bout de planche, en cm
162 $font = $this->yurt->getConfig('crown', 'font');
163 $hgap = $this->yurt->getConfig('crown', 'hgap'); // espace inutile laissé au bord gauche de l'image
164 $vgap = $this->yurt->getConfig('crown', 'vgap'); // espace inutile laissé au bord haut de l'image
165 $fs = $this->yurt->getConfig('crown', 'fs'); // font size
166 $scaleV = $this->yurt->getConfig('crown', 'scaleV'); // facteur d'echelle vertical; 1 cm <--> $scaleV px
167 $scaleH = $this->yurt->getConfig('crown', 'scaleH'); // facteur d'echelle horizontal ; 1 cm <--> $scaleH px
168 $pointSize = $this->yurt->getConfig('crown', 'pointSize');
169
170 // calculs
171 $wpc_m = $wpc; // wpc in m
172 $wpc *= 100; // convert to cm
173 $hgap += 2*$fs;
174 $vgap += 2*$fs;
175 $rc = $dc / 2;
176 $dci = $dc - 2*$hc;
177 $rci = $dci / 2;
178 // On recalcule gamma (deja fait dans main())
179 $gamma1 = acos(($rc - $wpc_m) / ($rc - $hc)); // radians
180 $gamma1_deg = 180 * $gamma1 / M_PI;
181 $npc1 = ceil(360/(2*$gamma1_deg));
182 $gamma_deg = 180 / $npc1;
183 $gamma = M_PI * $gamma_deg / 180;
184 // Calcul des coordonnees
185 $n = floor($gamma_deg / $step);
186 for($i=0; $i <= $n; $i++){
187 $gammai_deg = $i * $step;
188 $gammai = $gammai_deg * M_PI / 180;
189 // Coord des points Ai et Bi
190 $xA = round($rc * sin($gammai) * 100, 1);
191 $yA = round(($rc * cos($gammai) - $rci * cos($gamma)) * 100, 1);
192 $xB = round($rci * sin($gammai) * 100, 1);
193 $yB = round($rci * (cos($gammai) - cos($gamma)) * 100, 1);
194 // transformation pour mesures pratiques
195 $data[$n - $i]['gammai_deg'] = $gamma_deg - $gammai_deg;
196 $data[$i + $n]['gammai_deg'] = $gamma_deg + $gammai_deg;
197 $data[$n - $i]['xA'] = $lbpc/2 - $xA;
198 $data[$i + $n]['xA'] = $lbpc/2 + $xA;
199 $data[$n - $i]['yA'] = $yA;
200 $data[$i + $n]['yA'] = $yA;
201 $data[$n - $i]['xB'] = $lbpc/2 - $xB;
202 $data[$i + $n]['xB'] = $lbpc/2 + $xB;
203 $data[$n - $i]['yB'] = $yB;
204 $data[$i + $n]['yB'] = $yB;
205 }
206 // Dimensions de l'image
207 $w = $lbpc * $scaleH + 2*$hgap;
208 $h = $wpc * $scaleV + 2*$vgap;
209 // Creation de l'image
210 $img = imagecreate($w, $h);
211 $white = imagecolorallocate($img, 255, 255, 255);
212 $black = imagecolorallocate($img, 0, 0, 0);
213 // Pour les lignes pointille
214 $style = array($black, $black, $black, $black, $black, $white, $white, $white, $white, $white);
215 imagesetstyle($img, $style);
216
217 for($i=0; $i <= 2*$n; $i++){
218 // dessin de Ai
219 $x = $data[$i]['xA'] * $scaleH + $hgap;
220 $y = ($wpc - $data[$i]['yA']) * $scaleV + $vgap;
221 imagefilledellipse($img, $x, $y, $pointSize, $pointSize, $black);
222 imageLine($img, $x, $y, $x, $vgap-$fs+2, IMG_COLOR_STYLED);
223 imagettftext($img, $fs, 0, $x-$fs, $vgap-$fs, $black, $font, round($data[$i]['xA'], 1));
224 imagettftext($img, $fs, 0, $x+$pointSize+1, $y+$fs/2, $black, $font, round($data[$i]['yA'], 1));
225 // dessin de Bi
226 $x = $data[$i]['xB'] * $scaleH + $hgap;
227 $y = ($wpc - $data[$i]['yB']) * $scaleV + $vgap;
228 imagefilledellipse($img, $x, $y, $pointSize, $pointSize, $black);
229 imageLine($img, $x, $y, $x, $h-5-$fs-2, IMG_COLOR_STYLED);
230 imagettftext($img, $fs, 0, $x-$fs, $h-5, $black, $font, round($data[$i]['xB'], 1));
231 imagettftext($img, $fs, 0, $x+$pointSize+1, $y+$fs/2, $black, $font, round($data[$i]['yB'], 1));
232 }
233 // Dessin des bords
234 $x1 = $data[0]['xA'] * $scaleH + $hgap;
235 $y1 = ($wpc - $data[0]['yA']) * $scaleV + $vgap;
236 $x2 = $data[0]['xB'] * $scaleH + $hgap;
237 $y2 = ($wpc - $data[0]['yB']) * $scaleV + $vgap;
238 imageLine($img, $x1, $y1, $x2, $y2, $black);
239 $x1 = $data[2*$n]['xA'] * $scaleH + $hgap;
240 $y1 = ($wpc - $data[2*$n]['yA']) * $scaleV + $vgap;
241 $x2 = $data[2*$n]['xB'] * $scaleH + $hgap;
242 $y2 = ($wpc - $data[2*$n]['yB']) * $scaleV + $vgap;
243 imageLine($img, $x1, $y1, $x2, $y2, $black);
244 return $img;
245 }// end plank
246
247
248 }// end class Crown
249
250 ?>