#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# Pyromaths
# Un programme en Python qui permet de créer des fiches d'exercices types de
# mathématiques niveau collège ainsi que leur corrigé en LaTeX.
# Copyright (C) 2006 -- Jérôme Ortais (jerome.ortais@pyromaths.org)
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#
import random
from math import atan, cos, pi, sin, floor, ceil
#===============================================================================
# Symétrique d'une figure par rapport à une droite avec quadrillage
#===============================================================================
def valeurs_quad2(nb_pts):
vals = []
for i in range(nb_pts):
angle = random.randrange((i * 360) / nb_pts, ((i + 1) * 360) /
nb_pts)
vals.append(((random.randrange(1, 7) * .5) * cos((angle * pi) /
180), (random.randrange(1, 7) * .5) * sin((angle *
pi) / 180)))
return vals
def valeurs_quad(nb_pts):
vals = []
for i in range(nb_pts):
(alpha, beta) = ((i * 360) / nb_pts, ((i + 1) * 360) / nb_pts)
(x, y) = (0, 0)
while x == 0 or angle < alpha or angle > beta:
(x, y) = (random.randrange(-6, 7) * .5, random.randrange(-6,
7) * .5)
if x > 0:
angle = int((atan((y * 1.0) / x) * 180) / pi + 360) % \
360
if x < 0:
angle = int((atan((y * 1.0) / x) * 180) / pi + 180)
vals.append((x, y))
return vals
def place_pts(vals, angle):
txt = [" \\pstGeonode[PointSymbol=x,PointName=none]"]
for i in range(len(vals)):
txt.append("(%s,%s)" % vals[i])
txt.append("{%s}" % chr(i + 97))
txt.append("\n\\pstGeonode[PointSymbol=none,PointName=none](-4.5;%s){A}(4.5;%s){B}" % (angle, angle))
txt.append("\n\\psline[linecolor=Black, linewidth=1pt, nodesep=-4.5](A)(B)")
txt.append("\n\\pspolygon[linecolor=Maroon, linewidth=1pt]")
for i in range(len(vals)):
txt.append("(%s)" % chr(i + 97))
return ("").join(txt)
def Symetrie_quiz(angle, vals, nbpts):
langles = [0, 90, 45, 135]
langles.remove(angle)
angle2 = langles.pop(random.randrange(len(langles)))
angle3 = langles.pop(random.randrange(len(langles)))
vals_cor = [[vals,angle], [vals,angle2], [vals,angle3]]
random.shuffle(vals_cor)
quiz_txt = "$$\\fs1\\picture(570,140){"
quiz_txt += "(10,10){\\line(120,0)}(10,9){\\line(120,0)}(10,10){\\line(0,120)}(9,10){\\line(0,120)}" # Recuadro
quiz_txt += "(130,130){\\line(-120,0)}(130,129){\\line(-120,0)}(130,130){\\line(0,-120)}(129,130){\\line(0,-120)}"
quiz_txt += ("%s{\\bullet}%s{\\bullet}%s{\\bullet}%s{\\bullet}%s{\\bullet}" %
tuple(["("+str(i[0]*20+68)+","+str(i[1]*20+68)+")" for i in vals])) # puntos 1ºFigura
quiz_txt += ("%s%s%s%s%s" % tuple([union_m(vals[i-1],vals[i],70) for i in range(nbpts)])) # rectas 1ºFigura
quiz_txt += "(260,100){\\fs3\\fbox{1^o}}(400,100){\\fs3\\fbox{2^o}}(540,100){\\fs3\\fbox{3^o}}" # Numeración
count_vals = 0
for v in vals_cor:
if v[1] == 0:
quiz_txt += ("%s{\\bullet}%s{\\bullet}%s{\\bullet}%s{\\bullet}%s{\\bullet}" %
tuple(["("+str(i[0]*20+208+count_vals*140)+","+str(i[1]*-20+68)+")" for i in v[0]])) # puntos demás Figura
quiz_txt += ("%s%s%s%s%s" %
tuple([union_m(v[0][i-1],v[0][i],210+count_vals*140,v[1]) for i in range(nbpts)])) # rectas demás Figura
if v[1] == angle:
quiz_txt += "(10,70){\\line(120,0)}"
elif v[1] == 90:
quiz_txt += ("%s{\\bullet}%s{\\bullet}%s{\\bullet}%s{\\bullet}%s{\\bullet}" %
tuple(["("+str(i[0]*-20+208+count_vals*140)+","+str(i[1]*20+68)+")" for i in v[0]])) # puntos demás Figura
quiz_txt += ("%s%s%s%s%s" %
tuple([union_m(v[0][i-1],v[0][i],210+count_vals*140,v[1]) for i in range(nbpts)])) # rectas demás Figura
if v[1] == angle:
quiz_txt += "(70,10){\\line(0,120)}"
elif v[1] == 45:
quiz_txt += ("%s{\\bullet}%s{\\bullet}%s{\\bullet}%s{\\bullet}%s{\\bullet}" %
tuple(["("+str(i[1]*20+208+count_vals*140)+","+str(i[0]*20+68)+")" for i in v[0]])) # puntos demás Figura
quiz_txt += ("%s%s%s%s%s" %
tuple([union_m(v[0][i-1],v[0][i],210+count_vals*140,v[1]) for i in range(nbpts)])) # rectas demás Figura
if v[1] == angle:
quiz_txt += "(10,10){\\line(120,120)}"
elif v[1] == 135:
quiz_txt += ("%s{\\bullet}%s{\\bullet}%s{\\bullet}%s{\\bullet}%s{\\bullet}" %
tuple(["("+str(i[1]*-20+208+count_vals*140)+","+str(i[0]*-20+68)+")" for i in v[0]])) # puntos demás Figura
quiz_txt += ("%s%s%s%s%s" %
tuple([union_m(v[0][i-1],v[0][i],210+count_vals*140,v[1]) for i in range(nbpts)])) # rectas demás Figura
if v[1] == angle:
quiz_txt += "(10,130){\\line(120,-120)}"
count_vals += 1
quiz_txt += "}$$
\n"
quiz_sol = ""
for x in range(3):
if vals_cor[x][1] == angle:
quiz_sol += (u"~=%sº" % str(x+1))
else:
quiz_sol += (u"~%sº" % str(x+1))
return quiz_txt, quiz_sol
def union_m(pt1, pt2, d_m, type_m=-1):
if type_m == 0:
pt1_m = (pt1[0], -pt1[1])
pt2_m = (pt2[0], -pt2[1])
elif type_m == 90:
pt1_m = (-pt1[0], pt1[1])
pt2_m = (-pt2[0], pt2[1])
elif type_m == 45:
pt1_m = (pt1[1], pt1[0])
pt2_m = (pt2[1], pt2[0])
elif type_m == 135:
pt1_m = (-pt1[1], -pt1[0])
pt2_m = (-pt2[1], -pt2[0])
else:
pt1_m = pt1
pt2_m = pt2
v_x = (pt2_m[0] - pt1_m[0])*20
v_y = (pt2_m[1] - pt1_m[1])*20
return ("(%s,%s){\\line(%s,%s)}" %(pt1_m[0]*20 + d_m, pt1_m[1]*20 + 70, v_x, v_y))
def SymetrieQuadrillage():
exo = ["\\exercice", _(u"Construire la symétrique de chacune des figures par rapport à la droite en"), _(u"utilisant le quadrillage :\\par"), "\\psset{unit=.9cm}"]
cor = ["\\exercice*", _(u"Construire la symétrique de chacune des figures par rapport à la droite en"), _(u"utilisant le quadrillage :\\par"), "\\psset{unit=.9cm}"]
quiz = ["cloze"]
nbpts = 5
langles = [0, 90, 45, 135]
for j in range(3):
angle = langles.pop(random.randrange(len(langles)))
vals = valeurs_quad(nbpts)
txt = place_pts(vals, angle)
exo.append("\\begin{pspicture*}(-3,-3)(3,3)")
exo.append("\\psgrid[subgriddiv=2,gridlabels=0pt]")
exo.append(txt)
cor.append("\\begin{pspicture*}(-3,-3)(3,3)")
cor.append("\\psgrid[subgriddiv=2,gridlabels=0pt]")
cor.append(txt)
txt_cor = "\\pstOrtSym[PointSymbol=x,PointName=none]{A}{B}{"
for i in range(len(vals)):
if i > 0:
txt_cor += ","
txt_cor += "%s" % chr(i + 97)
txt_cor += "}["
for i in range(len(vals)):
if i > 0:
txt_cor += ","
txt_cor += "%s1" % chr(i + 97)
txt_cor += "]\n \pspolygon[linecolor=Black, linestyle=dashed, linewidth=1pt]"
for i in range(len(vals)):
txt_cor += "(%s1)" % chr(i + 97)
cor.append(txt_cor)
exo.append("\\end{pspicture*}")
cor.append("\\end{pspicture*}")
if j < 2:
exo.append("\\hfill")
cor.append("\\hfill")
quiz_nom = (_(u"Symétrie axiale %s") % str(j+1))
quiz_exo_cor = _(u"Indique quel c'est le symétrique au sujet de la droite de la figure encadrée de la gauche:
\n")
quiz_txt, quiz_sol = Symetrie_quiz(angle, vals, nbpts)
quiz_exo_cor += quiz_txt
quiz_exo_cor += (_(u"Réponse: La symétrique en ce qui concerne la droite est le {1:MULTICHOICE:%s}") %
quiz_sol)
quiz.append([quiz_nom, quiz_exo_cor, ""])
return (exo, cor, quiz)