1 | #!/usr/bin/python |
---|
2 | # -*- coding: utf-8 -*- |
---|
3 | # |
---|
4 | # Pyromaths |
---|
5 | # Un programme en Python qui permet de créer des fiches d'exercices types de |
---|
6 | # mathématiques niveau collège ainsi que leur corrigé en LaTeX. |
---|
7 | # Copyright (C) 2006 -- Jérôme Ortais (jerome.ortais@pyromaths.org) |
---|
8 | # |
---|
9 | # This program is free software; you can redistribute it and/or modify |
---|
10 | # it under the terms of the GNU General Public License as published by |
---|
11 | # the Free Software Foundation; either version 2 of the License, or |
---|
12 | # (at your option) any later version. |
---|
13 | # |
---|
14 | # This program is distributed in the hope that it will be useful, |
---|
15 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
16 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
17 | # GNU General Public License for more details. |
---|
18 | # |
---|
19 | # You should have received a copy of the GNU General Public License |
---|
20 | # along with this program; if not, write to the Free Software |
---|
21 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
---|
22 | # |
---|
23 | |
---|
24 | |
---|
25 | # #- additions / soustractions de vecteurs ( difficulté : ne pas sortir du cadre ) |
---|
26 | # #- multiplication d'un vecteur par un réel + add + sous ( difficulté : ne pas sortir du cadre ) |
---|
27 | # #- lire les coordonnées d'un vecteur |
---|
28 | # #- placer un point B connaissant A et les coordonnées de vec{AB} : avec coordonnées ou i et j ( difficulté : ne pas sortir du cadre ) |
---|
29 | # #- calcul de norme |
---|
30 | # #- simplifier des sommes |
---|
31 | # #- problèmes de colinéarité |
---|
32 | |
---|
33 | from pyromaths.classes.Vecteurs import randvect, Vecteur |
---|
34 | from pyromaths.classes.Racine import simplifie_racine |
---|
35 | import math |
---|
36 | from random import randint, shuffle |
---|
37 | |
---|
38 | def dist_bords(a, b): |
---|
39 | '''Calcule les distances minimales d'un point de coordonnées (a,b) aux bords du cadre, selon l'axe x et y.''' |
---|
40 | x = min(a, 18 - a) # la largeur vaut 18 |
---|
41 | y = min(b, 10 - b) # la hauteur vaut 10 |
---|
42 | return (x, y) |
---|
43 | |
---|
44 | def pair(n): |
---|
45 | '''Retourne le plus petit entier pair strictement plus grand que n''' |
---|
46 | if (n % 2 == 0): |
---|
47 | return n + 2 |
---|
48 | else: |
---|
49 | return n + 1 |
---|
50 | |
---|
51 | def AffNom(u, crd=0): |
---|
52 | '''Renvoie les coordonnées pour l'affichage du nom du vecteur u.''' |
---|
53 | if u.x == 0 and math.fabs(u.y) > 2: |
---|
54 | coord = (0, u.y / 2) |
---|
55 | elif u.x == 0: |
---|
56 | coord = (-0.5, u.y / 2) |
---|
57 | elif u.y == 0 and math.fabs(u.x) > 2: |
---|
58 | coord = (u.x / 2, 0) |
---|
59 | elif u.y == 0: |
---|
60 | coord = (u.x / 2, -0.5) |
---|
61 | elif math.fabs(u.x) + math.fabs(u.y) < 3: |
---|
62 | coord = (u.x / 2.0 + 0.5, u.y / 2.0 + 0.5) |
---|
63 | else: |
---|
64 | coord = (u.x / 2, u.y / 2) |
---|
65 | return str(coord[0]) + "," + str(coord[1]) |
---|
66 | |
---|
67 | def ChoixVecteur(u, v, w, x, y): |
---|
68 | listecoeff = [0.5, -0.5, -1, -2, 2, 3, -3] |
---|
69 | listevect = [(u, "u"), (v, "v"), (w, "w")] |
---|
70 | shuffle(listecoeff) |
---|
71 | shuffle(listevect) |
---|
72 | for vec in listevect: |
---|
73 | for coeff in listecoeff: |
---|
74 | if (0 <= x + coeff * vec[0].x <= 18) and (0 <= y + coeff * vec[0].y <= 10): |
---|
75 | return (coeff, coeff * vec[0], vec[1]) |
---|
76 | |
---|
77 | |
---|
78 | |
---|
79 | def repr_somme(u, v, u1, u2, cor, larg=0): |
---|
80 | '''Représente la somme des vecteurs u + v.''' |
---|
81 | |
---|
82 | a = u + v |
---|
83 | |
---|
84 | if (u.x * a.x >= 0): |
---|
85 | largeur = max(math.fabs(u.x), math.fabs(a.x)) |
---|
86 | if (a.x > 0): |
---|
87 | departx = 0 |
---|
88 | elif (a.x == 0): |
---|
89 | departx = -u.x / 2.0 + math.fabs(u.x) / 2 |
---|
90 | else: |
---|
91 | departx = max(math.fabs(u.x), math.fabs(a.x)) |
---|
92 | else: |
---|
93 | largeur = math.fabs(u.x) + math.fabs(a.x) |
---|
94 | if (u.x >= 0): |
---|
95 | departx = -a.x |
---|
96 | else: |
---|
97 | departx = -u.x |
---|
98 | if (u.y * a.y >= 0): |
---|
99 | hauteur = max(math.fabs(u.y), math.fabs(a.y)) |
---|
100 | if (a.y > 0): |
---|
101 | departy = 0 |
---|
102 | elif (a.y == 0): |
---|
103 | departy = -u.y / 2.0 + math.fabs(u.y) / 2 |
---|
104 | else: |
---|
105 | departy = max(math.fabs(u.y), math.fabs(a.y)) |
---|
106 | else: |
---|
107 | hauteur = math.fabs(u.y) + math.fabs(a.y) |
---|
108 | if (u.y >= 0): |
---|
109 | departy = -a.y |
---|
110 | else: |
---|
111 | departy = -u.y |
---|
112 | |
---|
113 | if int(larg) + largeur > 18: |
---|
114 | cor.append("\\par") # Figure trop large avec la précédente, il faut passer à une nouvelle ligne. |
---|
115 | |
---|
116 | depart = "(" + str(departx) + "," + str(departy) + ")" |
---|
117 | largeur = str(pair(int(largeur))) |
---|
118 | hauteur = str(pair(int(hauteur))) |
---|
119 | |
---|
120 | cor.append(u"\\begin{pspicture*}(0,0)(" + largeur + "," + hauteur + ")") |
---|
121 | cor.append(u"\\psgrid[subgriddiv=2, gridlabels=0pt]") |
---|
122 | cor.append(u"\\psset{unit=10mm,arrowscale=2}") |
---|
123 | |
---|
124 | cor.append(u"\\rput" + depart + "{") |
---|
125 | cor.append(u"\\psline[linewidth=1pt, linecolor=DarkGreen]{|->}(0, 0)(" + str(u.x) + ", " + str(u.y) + ")") # # Premier Vecteur |
---|
126 | cor.append(u"\\rput(" + AffNom(u) + ") \ |
---|
127 | {\\psframebox[linecolor=white, fillcolor=white, fillstyle=solid]{\\textcolor{DarkGreen}{$\\overrightarrow{" + u1 + "}$}}}") |
---|
128 | |
---|
129 | cor.append(u"\\psline[linewidth=1pt, linecolor=DarkBlue]{|->}(" + str(u.x) + ", " + str(u.y) + ")(" + str(a.x) + ", " + str(a.y) + ")") # # 2e Vecteur |
---|
130 | k = Vecteur(u.x + a.x, u.y + a.y) |
---|
131 | cor.append(u"\\rput(" + AffNom(k) + ") \ |
---|
132 | {\psframebox[linecolor=white, fillcolor=white, fillstyle=solid]{\\textcolor{DarkBlue}{$\\overrightarrow{" + u2 + "}$}}}") |
---|
133 | if len(u2) > 1: |
---|
134 | sgn = "-" |
---|
135 | else: |
---|
136 | sgn = "+" |
---|
137 | cor.append(u"\\psline[linestyle=dashed, linewidth=1pt, linecolor=DarkRed]{|->}(0, 0)(" + str(a.x) + ", " + str(a.y) + ")") # # Résultat de l'opération |
---|
138 | cor.append(u"\\rput(" + AffNom(a) + ") \ |
---|
139 | {\psframebox[linecolor=white, fillcolor=white, fillstyle=solid]{\\textcolor{DarkRed}{$\\overrightarrow{" + u1 + "}" + sgn + "\\overrightarrow{" + u2[-1] + "}$}}}") |
---|
140 | |
---|
141 | cor.append(u"}") |
---|
142 | cor.append(u"\\end{pspicture*}") |
---|
143 | return largeur # # récupérer la largeur pour éviter d'aligner des figures trop larges sur la feuille |
---|
144 | |
---|
145 | def vecteurs_add(): |
---|
146 | '''Exercice sur la définition des vecteurs et leurs sommes.''' |
---|
147 | t = None |
---|
148 | while not t: |
---|
149 | # Pour être sûr que l'exercice ait des solutions |
---|
150 | (u, posux, posuy) = randvect(0, 10) |
---|
151 | (v, posvx, posvy) = randvect(math.fabs(u.x) + 1, 10) |
---|
152 | (w, poswx, poswy) = randvect(math.fabs(v.x) + math.fabs(u.x) + 2, 10) |
---|
153 | |
---|
154 | # # Construction du point pour la question 2 |
---|
155 | if 18 - poswx - max(w.x, 0) > 0: |
---|
156 | restes = (18 - poswx - max(w.x, 0), 10) |
---|
157 | pointy = randint(0, 10) |
---|
158 | elif poswy + min(w.y, 0) > 10 - poswy - max(w.y, 0): |
---|
159 | restes = (poswx + min(w.x, 0), poswy + min(w.y, 0)) |
---|
160 | pointy = randint(0, restes[1]) |
---|
161 | else: |
---|
162 | restes = (poswx + min(w.x, 0), 10 - poswy - max(w.y, 0)) |
---|
163 | pointy = randint(10 - restes[1], 10) |
---|
164 | |
---|
165 | pointx = randint(18 - restes[0], 18) |
---|
166 | |
---|
167 | t = ChoixVecteur(u, v, w, pointx, pointy) |
---|
168 | |
---|
169 | exo = ["\\exercice"] |
---|
170 | cor = ["\\exercice*"] |
---|
171 | |
---|
172 | exo.append(u"\\begin{pspicture*}(0,0)(18,10)") |
---|
173 | exo.append(u"\\psgrid[subgriddiv=2, gridlabels=0pt]") |
---|
174 | exo.append(u"\\psset{unit=10mm,arrowscale=2}") |
---|
175 | |
---|
176 | cor.append(u"\\begin{pspicture*}(0,0)(18,10)") |
---|
177 | cor.append(u"\\psgrid[subgriddiv=2, gridlabels=0pt]") |
---|
178 | cor.append(u"\\psset{unit=10mm,arrowscale=2}") |
---|
179 | |
---|
180 | exo.append(u"\\psdot(" + str(pointx) + "," + str(pointy) + ")") |
---|
181 | |
---|
182 | if pointx < 18 and pointy < 10: |
---|
183 | nompoint = str(pointx + 0.5) + "," + str(pointy + 0.5) |
---|
184 | else: |
---|
185 | nompoint = str(pointx - 0.5) + "," + str(pointy - 0.5) |
---|
186 | |
---|
187 | exo.append(u"\\rput(" + nompoint + "){\\psframebox[linecolor=white, fillcolor=white, fillstyle=solid]{$A$}}") |
---|
188 | |
---|
189 | cor.append(u"\\psdot(" + str(pointx) + "," + str(pointy) + ")") |
---|
190 | cor.append(u"\\rput(" + nompoint + "){\\psframebox[linecolor=white, fillcolor=white, fillstyle=solid]{$A$}}") |
---|
191 | |
---|
192 | cor.append(u"\psline[linecolor=DarkBlue]{|->}(" + str(pointx) + "," + str(pointy) + ")(" + str(pointx + t[1].x) + ", " + str(pointy + t[1].y) + ")") |
---|
193 | |
---|
194 | bx = pointx + t[1].x |
---|
195 | by = pointy + t[1].y |
---|
196 | |
---|
197 | if bx < 18 and by < 10: |
---|
198 | nompoint = str(bx + 0.5) + "," + str(by + 0.5) |
---|
199 | else: |
---|
200 | nompoint = str(bx - 0.5) + "," + str(by - 0.5) |
---|
201 | |
---|
202 | cor.append(u"\\psdot(" + str(pointx + t[1].x) + "," + str(pointy + t[1].y) + ")") |
---|
203 | cor.append(u"\\rput(" + nompoint + "){\\psframebox[linecolor=white, fillcolor=white, fillstyle=solid]{$B$}}") |
---|
204 | |
---|
205 | for vec in [(u, posux, posuy, "u"), (v, posvx, posvy, "v"), (w, poswx, poswy, "w")]: |
---|
206 | exo.append(u"\\rput(" + str(vec[1]) + "," + str(vec[2]) + "){") |
---|
207 | exo.append(u"\psline{|->}(0, 0)(" + str(vec[0].x) + ", " + str(vec[0].y) + ")") |
---|
208 | |
---|
209 | exo.append(u"\\rput(" + AffNom(vec[0]) + ") \ |
---|
210 | {\\psframebox[linecolor=white, fillcolor=white, fillstyle=solid]{$\\overrightarrow{" + vec[3] + "}$}}") |
---|
211 | exo.append(u"}") |
---|
212 | exo.append(u"\\end{pspicture*}") |
---|
213 | |
---|
214 | |
---|
215 | for vec in [(u, posux, posuy, "u"), (v, posvx, posvy, "v"), (w, poswx, poswy, "w")]: |
---|
216 | if vec[0].y > 0: |
---|
217 | plus = 1 |
---|
218 | else: |
---|
219 | plus = 0 |
---|
220 | cor.append(u"\\rput(" + str(vec[1]) + "," + str(vec[2]) + "){") |
---|
221 | cor.append(u"\\psline{|->}(0, 0)(" + str(vec[0].x) + ", " + str(vec[0].y) + ")") |
---|
222 | cor.append(u"\\psline[linestyle=dashed,linecolor=DarkRed](0, 0)(" + str(vec[0].x) + ", 0)(" + str(vec[0].x) + "," + str(vec[0].y) + ")") |
---|
223 | cor.append(u"\\rput(" + AffNom(vec[0]) + "){\\psframebox[linecolor=white, fillcolor=white, \ |
---|
224 | fillstyle=solid]{$\\overrightarrow{" + vec[3] + "}\\ (" + str(vec[0].x) + ";" + str(vec[0].y) + ")$}}") |
---|
225 | cor.append(u"}") |
---|
226 | cor.append(u"\\end{pspicture*}") |
---|
227 | |
---|
228 | exo.append("\\par") |
---|
229 | cor.append("\\par") |
---|
230 | exo.append(_(u"On se place dans un repère orthonormé et on considère les vecteurs $\\overrightarrow{u}$, $\\overrightarrow{v}$, et $\\overrightarrow{w}$ ci-dessous.")) |
---|
231 | cor.append(_(u"On se place dans un repère orthonormé et on considère les vecteurs $\\overrightarrow{u}$, $\\overrightarrow{v}$, et $\\overrightarrow{w}$ ci-dessous.")) |
---|
232 | |
---|
233 | exo.append("\\begin{enumerate}") |
---|
234 | cor.append("\\begin{enumerate}") |
---|
235 | |
---|
236 | exo.append(_(u"\\item Lire les coordonnées de chacun des vecteurs $\\overrightarrow{u}$, $\\overrightarrow{v}$, et $\\overrightarrow{w}$.")) |
---|
237 | cor.append(_(u"\\item Lire les coordonnées de chacun des vecteurs $\\overrightarrow{u}$, $\\overrightarrow{v}$, et $\\overrightarrow{w}$.")) |
---|
238 | |
---|
239 | cor.append("\\par") |
---|
240 | cor.append(_(u"Un petit rappel : l'abscisse d'un vecteur est la différence d'abscisse entre le fin et le début du vecteur. \ |
---|
241 | Concernant le vecteur $\\overrightarrow{u}$, son abscisse est $") + str(u.x) + _(u"$. \ |
---|
242 | On lit également son ordonnée : $") + str(u.x) + _(u"$. \ |
---|
243 | Donc les coordonnées de $\\overrightarrow{u}$ sont $(") + str(u.x) + ", " + str(u.y) + _(u" )$. \ |
---|
244 | Des pointillés ont été ajoutés sur la figure pour faciliter la lecture des coordonnées.")) |
---|
245 | cor.append(_(u"De même, les coordonnées de $\\overrightarrow{v}$ sont $(") + str(v.x) + ", " + str(v.y) + _(u" )$ \ |
---|
246 | et les coordonnées de $\\overrightarrow{w}$ sont $(") + str(w.x) + ", " + str(w.y) + " )$.") |
---|
247 | |
---|
248 | exo.append(_(u"\\item Placer un point B de sorte que le vecteur $\\overrightarrow{AB}$ soit égal à $") + str(t[0]) + " \\times \\overrightarrow{" + t[2] + "}$.") |
---|
249 | cor.append(_(u"\\item Placer un point B de sorte que le vecteur $\\overrightarrow{AB}$ soit égal à $") + str(t[0]) + " \\times \\overrightarrow{" + t[2] + "}$.") |
---|
250 | |
---|
251 | cor.append(u"\\par") |
---|
252 | cor.append(_(u"Le plus simple pour répondre à cette question est de calculer les coordonnées du vecteur $") + str(t[0]) + " \\times \\overrightarrow{" + str(t[2]) + "}$.") |
---|
253 | cor.append(_(u"Cela se fait en multipliant les coordonnées de $\\overrightarrow{") + str(t[2]) + "}$ par $" + str(t[0]) + _(u"$, ce qui donne comme résultat $(") + str(t[1].x) + ";" + str(t[1].y) + ")$.") |
---|
254 | cor.append(_(u"En partant du point A et en respectant ces coordonnées, on dessine un vecteur (en bleu sur la figure ci-dessus) qui indique l'emplacement du point B.")) |
---|
255 | |
---|
256 | exo.append(_(u"\\item Calculer les normes de chacun des vecteurs $\\overrightarrow{u}$, $\\overrightarrow{v}$, et $\\overrightarrow{w}$.")) |
---|
257 | cor.append(_(u"\\item Calculer les normes de chacun des vecteurs $\\overrightarrow{u}$, $\\overrightarrow{v}$, et $\\overrightarrow{w}$.")) |
---|
258 | |
---|
259 | if u.x ** 2 + u.y ** 2 == simplifie_racine(u.x ** 2 + u.y ** 2)[1]: # Cas où la simplification est la même, donc inutile d'écrire deux fois la même chose. |
---|
260 | Norm_u = "$" |
---|
261 | else: |
---|
262 | Norm_u = "=" + str(u.normeTex()) + "$" |
---|
263 | |
---|
264 | if v.x ** 2 + v.y ** 2 == simplifie_racine(v.x ** 2 + v.y ** 2)[1]: |
---|
265 | Norm_v = "$" |
---|
266 | else: |
---|
267 | Norm_v = "=" + str(v.normeTex()) + "$" |
---|
268 | |
---|
269 | if w.x ** 2 + w.y ** 2 == simplifie_racine(w.x ** 2 + w.y ** 2)[1]: |
---|
270 | Norm_w = "$" |
---|
271 | else: |
---|
272 | Norm_w = "=" + str(w.normeTex()) + "$" |
---|
273 | |
---|
274 | cor.append("\\par") |
---|
275 | cor.append(u"$\|\\overrightarrow{u}\|=\\sqrt{(" + str(u.x) + ")^2+(" + str(u.y) + ")^2}=\\sqrt{" + str(u.x ** 2) + " + " + str(u.y ** 2) + "}= \ |
---|
276 | \\sqrt{" + str(u.x ** 2 + u.y ** 2) + "}" + Norm_u + ".\\par") |
---|
277 | cor.append(_(u"De la même manière, on obtient :")) |
---|
278 | |
---|
279 | cor.append(u"$\|\\overrightarrow{v}\|=\\sqrt{(" + str(v.x) + ")^2+(" + str(v.y) + ")^2}=\\sqrt{" + str(v.x ** 2) + " + " + str(v.y ** 2) + "}= \ |
---|
280 | \\sqrt{" + str(v.x ** 2 + v.y ** 2) + "}" + Norm_v + " et \\par") |
---|
281 | cor.append(u"$\|\\overrightarrow{w}\|=\\sqrt{(" + str(w.x) + ")^2+(" + str(w.y) + ")^2}=\\sqrt{" + str(w.x ** 2) + " + " + str(w.y ** 2) + "}= \ |
---|
282 | \\sqrt{" + str(w.x ** 2 + w.y ** 2) + "}" + Norm_w + ".\\par") |
---|
283 | |
---|
284 | exo.append(_(u"\\item Dessiner des représentants des vecteurs $\\overrightarrow{u}+\\overrightarrow{v}$, $\\overrightarrow{u}-\\overrightarrow{v}$, $\\overrightarrow{u}-\\overrightarrow{w}$ \ |
---|
285 | et $\\overrightarrow{v}+\\overrightarrow{w}$.")) |
---|
286 | cor.append(_(u"\\item Dessiner des représentants des vecteurs $\\overrightarrow{u}+\\overrightarrow{v}$, $\\overrightarrow{u}-\\overrightarrow{v}$, $\\overrightarrow{u}-\\overrightarrow{w}$ \ |
---|
287 | et $\\overrightarrow{v}+\\overrightarrow{w}$.")) |
---|
288 | |
---|
289 | cor.append("\\par") |
---|
290 | cor.append(_(u"Pour dessiner les sommes ou différences de vecteurs, il faut les mettre \"bouts à bouts\", \ |
---|
291 | comme sur les figures qui suivent :\\par")) |
---|
292 | i = repr_somme(u, v, 'u', 'v', cor) |
---|
293 | repr_somme(u, -v, 'u', '-v', cor, i) |
---|
294 | cor.append("\\par") |
---|
295 | i = repr_somme(u, -w, 'u', '-w', cor) |
---|
296 | repr_somme(v, w, 'v', 'w', cor, i) |
---|
297 | |
---|
298 | exo.append("\\end{enumerate}") |
---|
299 | cor.append("\\end{enumerate}") |
---|
300 | |
---|
301 | return exo, cor |
---|
302 | |
---|
303 | vecteurs_add.description = _(u"Vecteurs") |
---|
304 | vecteurs_add.level = _(u"2.Seconde") |
---|