mathmaker  0.4(alpha)
mathmaker_dev/maintenance/autotest/obj_test/geo_test/right_triangle_test.py
00001 # -*- coding: utf-8 -*-
00002 
00003 # Mathmaker creates automatically maths exercises sheets
00004 # with their answers
00005 # Copyright 2006-2014 Nicolas Hainaux <nico_h@users.sourceforge.net>
00006 
00007 # This file is part of Mathmaker.
00008 
00009 # Mathmaker is free software; you can redistribute it and/or modify
00010 # it under the terms of the GNU General Public License as published by
00011 # the Free Software Foundation; either version 3 of the License, or
00012 # any later version.
00013 
00014 # Mathmaker is distributed in the hope that it will be useful,
00015 # but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017 # GNU General Public License for more details.
00018 
00019 # You should have received a copy of the GNU General Public License
00020 # along with Mathmaker; if not, write to the Free Software
00021 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00022 
00023 import os
00024 import sys
00025 #import locale
00026 
00027 #from utils import default
00028 
00029 from core import *
00030 from core.base_calculus import *
00031 from core.base_geometry import *
00032 from core.geometry import *
00033 
00034 from lib.common import pythagorean
00035 
00036 from maintenance.autotest import common
00037 
00038 #try:
00039 #   locale.setlocale(locale.LC_ALL, default.LANGUAGE + '.' + default.ENCODING)
00040 #except:
00041 #    locale.setlocale(locale.LC_ALL, '')
00042 
00043 check = common.check
00044 
00045 
00046 def action():
00047     if common.verbose:
00048         os.write(common.output, "--- [GEO] RIGHT TRIANGLE \n")
00049 
00050     # Don't forget to uncomment the convenient lines above if a test
00051     # requires to use the locale module.
00052 
00053     # 1
00054     t1 = RightTriangle((("A", "B", "C"),
00055                         {'leg0' : 4, 'leg1' : 3}
00056                        ),
00057                        rotate_around_isobarycenter='no'
00058                       )
00059     t1.leg0.set_label(Value(4, unit='cm'))
00060     t1.leg1.set_label(Value(3, unit='cm'))
00061     t1.hypotenuse.set_label(Value(5, unit='cm'))
00062 
00063     check(t1.into_euk(),
00064           ["box -0.6, -0.6, 4.6, 3.6"\
00065            "A = point(0, 0)"\
00066            "B = point(4, 0)"\
00067            "C = point(4, 3)"\
00068            "draw  (A.B.C)"\
00069            "  $\\rotatebox{0}{4 cm}$ A 0 - 7.5 deg 6.4"\
00070            "  $\\rotatebox{-90}{3 cm}$ B 90 - 9 deg 4.8"\
00071            "  $\\rotatebox{37}{5 cm}$ A 37 + 6.5 deg 8"\
00072            "end"\
00073            "label"\
00074            "  C, B, A right"\
00075            "  A 0 + 200 deg"\
00076            "  B 0 - 45 deg"\
00077            "  C 0 + 65 deg"\
00078            "end"])
00079 
00080     # 2
00081     t2 = RightTriangle((("Y", "E", "P"),
00082                         {'leg0' : 4, 'leg1' : 3}
00083                        ),
00084                        rotate_around_isobarycenter=30
00085                       )
00086     t2.leg0.set_label(Value(4, unit='cm'))
00087     t2.leg1.set_label(Value(3, unit='cm'))
00088     t2.hypotenuse.set_label(Value(5, unit='cm'))
00089 
00090     check(t2.into_euk(),
00091           ["box 0.26, -1.8, 4.92, 4.0"\
00092           "Y = point(0.86, -1.2)"\
00093           "E = point(4.32, 0.8)"\
00094           "P = point(2.82, 3.4)"\
00095           "draw"\
00096           "  (Y.E.P)"\
00097           "  $\\rotatebox{30}{4 cm}$ Y 30 - 7.5 deg 6.4"\
00098           "  $\\rotatebox{-60}{3 cm}$ E 120 - 8.9 deg 4.9"\
00099           "  $\\rotatebox{67}{5 cm}$ Y 67 + 6.5 deg 8.1"\
00100           "end"\
00101           "label"\
00102           "  P, E, Y right"\
00103           "  Y 30 + 200 deg"\
00104           "  E 30 - 45 deg"\
00105           "  P 30 + 65 deg"\
00106           "end"])
00107 
00108     # 3
00109     t3 = RightTriangle((("Z", "A", "K"),
00110                         {'leg0' : 3, 'leg1' : 4}
00111                        ),
00112                        rotate_around_isobarycenter=75
00113                       )
00114     t3.leg0.set_label(Value(3.2, unit='cm'))
00115     t3.leg1.set_label(Value(4.5, unit='cm'))
00116     t3.hypotenuse.set_label(Value(""))
00117 
00118     check(t3.into_euk(),
00119           ["box -0.92, -1.54, 4.15, 3.59"\
00120           "Z = point(2.77, -0.94)"\
00121           "A = point(3.55, 1.95)"\
00122           "K = point(-0.32, 2.99)"\
00123           "draw"\
00124           "  (Z.A.K)"\
00125           "  $\\rotatebox{75}{3,2 cm}$ Z 75 - 9.1 deg 4.8"\
00126           "  $\\rotatebox{-15}{4,5 cm}$ A 165 - 7.5 deg 6.5"\
00127           "end"\
00128           "label"\
00129           "  K, A, Z right"\
00130           "  Z 75 + 200 deg"\
00131           "  A 75 - 45 deg"\
00132           "  K 75 + 65 deg"\
00133           "end"])
00134 
00135     # 4
00136     t4 = RightTriangle((("L", "O", "P"),
00137                         {'leg0' : 2, 'leg1' : 7}
00138                        ),
00139                        rotate_around_isobarycenter=140
00140                       )
00141 
00142     t4.leg0.set_label(Value(1.5, unit='cm'))
00143     t4.leg1.set_label(Value(""))
00144     t4.hypotenuse.set_label(Value(7, unit='cm'))
00145     t4.angle0.set_mark("back")
00146     t4.angle2.set_mark("dotted")
00147     t4.angle0.set_label(Value(30, unit="\\textdegree"))
00148 
00149     check(t4.into_euk(),
00150           ["box -2.78, -1.41, 4.45, 5.15"\
00151           +"L = point(3.85, 3.26)"\
00152           +"O = point(2.32, 4.55)"\
00153           +"P = point(-2.18, -0.81)"\
00154           +"draw"\
00155           +"  (L.O.P)"\
00156           +"  $\\rotatebox{-40}{1,5 cm}$ L 140 - 17 deg 3.3"\
00157           +"  $\\rotatebox{34}{7 cm}$ L 214 + 5.1 deg 11.7"\
00158           +"  $\\rotatebox{-2.9}{30\\textdegree}$ L 177.1 deg 2.7"\
00159           +"end"\
00160           +"label"\
00161           +"  O, L, P back"\
00162           +"  P, O, L right"\
00163           +"  L, P, O dotted"\
00164           +"  L 140 + 200 deg"\
00165           +"  O 140 - 45 deg"\
00166           +"  P 140 + 65 deg"\
00167           +"end"])
00168 
00169     # 5
00170     check(t4.pythagorean_substequality().into_str(),
00171           ["\\text{OP}^{2}=\\text{PL}^{2}-\\text{LO}^{2}"])
00172 
00173     # 6
00174     check(t4.pythagorean_substequality().substitute().into_str(),
00175           ["\\text{OP}^{2}=7^{2}-" + locale.str(1.5) + "^{2}"])
00176 
00177     # 7
00178     eq_t4 = Equation(t4.pythagorean_substequality().substitute())
00179     check(eq_t4.auto_resolution(dont_display_equations_name=True,
00180                                 decimal_result=HUNDREDTH,
00181                                 pythagorean_mode='yes',
00182                                 unit='cm'),
00183          [  "\[\\text{OP}^{2}=7^{2}-" + locale.str(1.5) + "^{2}\]" \
00184           + "\[\\text{OP}^{2}=49-" + locale.str(2.25) + "\]" \
00185           + "\[\\text{OP}^{2}=" + locale.str(46.75) + "\]" \
00186           + "\[\\text{OP}=\\sqrt{" + locale.str(46.75) \
00187           + "}\\text{ because \\text{OP} is positive.}\]"\
00188           + "\[\\text{OP}\\simeq" + locale.str(6.84) + "\\text{ cm}\]"])
00189 
00190     # 8
00191     # A small test about the research of matching legs... in pythagorean
00192     legs_matching_65_as_hyp=pythagorean.get_legs_matching_given_hypotenuse(65)
00193     check(str(legs_matching_65_as_hyp),
00194          [  "[16, 63, 25, 60, 33, 56, 39, 52]"])
00195 
00196     # 9
00197     legs_matching_36_as_a_side=pythagorean.get_legs_matching_given_leg(36)
00198     check(str(legs_matching_36_as_a_side),
00199          [  "[15, 27, 48, 77, 105, 160]"])
00200 
00201     # 10
00202     t5 = RightTriangle((("P", "A", "X"),
00203                         {'leg0' : 1, 'leg1' : 8}
00204                        ),
00205                        rotate_around_isobarycenter=0
00206                       )
00207 
00208     t5.leg0.set_label(Value(1, unit='cm'))
00209     t5.leg1.set_label(Value(8, unit='cm'))
00210     t5.hypotenuse.set_label(Value("?"))
00211     t5.angle0.set_mark("simple")
00212     t5.angle2.set_mark("double")
00213     t5.angle0.set_label(Value(64, unit="\\textdegree"))
00214     t5.angle2.set_label(Value(80, unit="\\textdegree"))
00215 
00216     check(t5.into_euk(),
00217           ["box -0.6, -0.6, 1.6, 8.6"\
00218           +"P = point(0, 0)"\
00219           +"A = point(1, 0)"\
00220           +"X = point(1, 8)"\
00221           +"draw"\
00222           +"  (P.A.X)"\
00223           +"  $\\rotatebox{0}{1 cm}$ P 0 - 25 deg 1.6"\
00224           +"  $\\rotatebox{-90}{8 cm}$ A 90 - 4.7 deg 12.8"\
00225           +"  $\\rotatebox{83}{?}$ P 83 + 4.7 deg 12.9"\
00226           +"  $\\rotatebox{41.4}{64\\textdegree}$ P 41.4 deg 2.7"\
00227           +"  $\\rotatebox{86.4}{80\\textdegree}$ X 266.4 deg 7.92"\
00228           +"end"\
00229           +"label"\
00230           +"  A, P, X simple"\
00231           +"  X, A, P right"\
00232           +"  P, X, A double"\
00233           +"  P 0 + 200 deg"\
00234           +"  A 0 - 45 deg"\
00235           +"  X 0 + 65 deg"\
00236           +"end"])