~ulrich3110/lorze/ulrich3110

« back to all changes in this revision

Viewing changes to Scripts/lrzkarpol.py

  • Committer: Andreas Ulrich
  • Date: 2012-12-13 20:54:19 UTC
  • Revision ID: ulrich3110@gmail.com-20121213205419-aucgdskqtqmyrj10
new file structure, new object structure, about dialogue, help dialogue, hep pages in english and german, german translation, ponton5h installer, documentation

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/python
2
 
# -*- coding: utf-8 -*-
3
 
 
4
 
# LORZE erasandcad, a 2D CAD with an intuitive user interface, simple and easy.
5
 
# http://erasand.jimdo.com/python-programme/lorze/
6
 
# (C) 2012, Andreas Ulrich
7
 
 
8
 
# This program is free software: you can redistribute it and/or modify
9
 
# it under the terms of the GNU General Public License as published by
10
 
# the Free Software Foundation, either version 3 of the License, or
11
 
# (at your option) any later version.
12
 
 
13
 
# This program is distributed in the hope that it will be useful,
14
 
# but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 
# GNU General Public License for more details.
17
 
 
18
 
# You should have received a copy of the GNU General Public License
19
 
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
 
 
21
 
import math
22
 
 
23
 
 
24
 
class KarAndPol():
25
 
 
26
 
    def __init__(self, options):
27
 
        # foat: width
28
 
        self.__width= 0.0
29
 
 
30
 
        # float: height
31
 
        self.__height= 0.0
32
 
 
33
 
        # float: angle
34
 
        self.__angle= 0.0
35
 
 
36
 
        # float: length
37
 
        self.__length= 0.0
38
 
 
39
 
        # integer: number of decimal places
40
 
        self.__dps= options.GetDezPlcs()
41
 
 
42
 
    def SetKar(self, width, height):
43
 
        # set width and height: float
44
 
        self.__width= float(width)
45
 
        self.__height= float(height)
46
 
 
47
 
    def SetPol(self, angle, length):
48
 
        # set angle and length: float
49
 
        self.__angle= float(angle)
50
 
        self.__length= float(length)
51
 
        if self.__angle >= 360:
52
 
            self.__angle= self.__angle% 360
53
 
        elif  self.__angle <= -360:
54
 
            self.__angle= (abs(self.__angle)% 360)* -1
55
 
 
56
 
    def GetKar(self):
57
 
        # get width and height from angle and length: float
58
 
        if self.__length== 0:
59
 
            return ((self.__width, self.__height))
60
 
 
61
 
        a= math.radians(self.__angle)
62
 
        w= math.cos(a)* self.__length
63
 
        h= math.sin(a)* self.__length
64
 
        self.__width= round(w, self.__dps)
65
 
        self.__height= round(h, self.__dps)
66
 
        return (self.__width, self.__height)
67
 
 
68
 
    def GetPol(self):
69
 
        # get angle and length from width and height: float
70
 
        if self.__width== 0 and self.__height== 0:
71
 
            return ((self.__width, self.__height))
72
 
        elif self.__width== 0 and self.__height> 0:
73
 
            self.__angle= 90
74
 
            self.__length= self.__height
75
 
        elif self.__width== 0 and self.__height< 0:
76
 
            self.__angle= 270
77
 
            self.__length= abs(self.__height)
78
 
        elif self.__width> 0 and self.__height== 0:
79
 
            self.__angle= 0
80
 
            self.__length= self.__width
81
 
        elif self.__width< 0 and self.__height== 0:
82
 
            self.__angle= 180
83
 
            self.__length= abs(self.__width)
84
 
        else:
85
 
            w= abs(self.__width)
86
 
            h= abs(self.__height)
87
 
            a= math.degrees(math.atan(h/w))
88
 
            l= math.sqrt(h**2+ w**2)
89
 
            if self.__height> 0 and self.__width< 0:
90
 
                a= 180- a
91
 
            elif self.__height< 0 and self.__width< 0:
92
 
                a+= 180
93
 
            elif self.__height<0 and self.__width> 0:
94
 
                a= 360- a
95
 
            self.__angle= round(a, self.__dps)
96
 
            self.__length= round(l, self.__dps)
97
 
        return (self.__angle, self.__length)
98
 
 
99
 
 
100
 
# Trigonometrie
101
 
# width= a, height= g, length= h, angle= w
102
 
# sin(w)= g/ h, g= sin(w)* h, h= g/ sin(w)
103
 
# cos(w)= a/ h, a= cos(w)* h, h= a/ cos(w)
104
 
# tan(w)= g/ a, g= tan(w)* a, a= g/ tan(w)
105
 
 
106
 
if __name__== '__main__':
107
 
    from lrzoptions import LorzeOptions
108
 
 
109
 
    options= LorzeOptions()
110
 
    test= KarAndPol(options)
111
 
    print(u'Test .SetPol() -> .GetKar()')
112
 
    for t in [(0, 256, '256, 0'),
113
 
              (65, 269, '113.684312408, 243.796794713'),
114
 
              (90, 326, '0, 326'),
115
 
              (148, 728, '-617.379014002, 385.781224362'),
116
 
              (180, 369, '-369, 0'),
117
 
              (259, 236, '-45.030922909, -231.664015294'),
118
 
              (270, 268, '0, -268'),
119
 
              (326, 687, '569.548812345, -384.165524684'),
120
 
              (360, 265, '265, 0'),
121
 
              (785, 584, '246.809064857, 529.283747629'),
122
 
              (-53, 59, '35.507086366, -47.119495093'),
123
 
              (-90, 12, '0, -12'),
124
 
              (-159, 25, '-23.339510662, -8.959198739'),
125
 
              (-180, 35, '-35, 0'),
126
 
              (-218, 37, '-29.156397883, 22.779474587'),
127
 
              (-270, 26, '0, 26'),
128
 
              (-289, 27, '8.79034017, 25.529001541'),
129
 
              (-360, 59, '59, 0'),
130
 
              (-489, 43, '-27.060776815, -33.417276343')]:
131
 
        a, l, control= t
132
 
        print(u'W, L: '+str(a)+ ', '+ str(l))
133
 
        print(u'control: '+ control)
134
 
        test.SetPol(a, l)
135
 
        w, h= test.GetKar()
136
 
        print(u'B, H:      '+ str(w)+ ',    '+ str(h))
137
 
    print(u'Test .SetKar() -> .GetPol()')
138
 
    for t in [(26, 0, '0, 26'),
139
 
              (65, 87, '53.235619324, 108.600184162'),
140
 
              (0, 69, '90, 69'),
141
 
              (-58, 56, '136.005086005, 80.622577483'),
142
 
              (-23, 0, '180, 23'),
143
 
              (-45, -39, '220.91438322, 59.548299724'),
144
 
              (0, -12, '270, 12'),
145
 
              (89, -28, '342.536073108, 93.300589494'),
146
 
              (256, 0, '0, 256'),
147
 
              (113.684312408, 243.796794713, '65, 269'),
148
 
              (0, 326, '90, 326'),
149
 
              (-617.379014002, 385.781224362, '148, 728'),
150
 
              (-369, 0, '180, 369'),
151
 
              (-45.030922909, -231.664015294, '259, 236'),
152
 
              (0, -268, '270, 268'),
153
 
              (569.548812345, -384.165524684, '326, 687'),
154
 
              (265, 0, '0, 265'),
155
 
              (246.809064857, 529.283747629, '65, 584'),
156
 
              (35.507086366, -47.119495093, '307, 59'),
157
 
              (0, -12, '270, 12'),
158
 
              (-23.339510662, -8.959198739, '201, 25'),
159
 
              (-35, 0, '180, 35'),
160
 
              (-29.156397883, 22.779474587, '142, 37'),
161
 
              (0, 26, '90, 26'),
162
 
              (8.79034017, 25.529001541, '71, 27'),
163
 
              (59, 0, '0, 59'),
164
 
              (-27.060776815, -33.417276343, '231, 43')]:
165
 
        w, h, control= t
166
 
        print(u'B, H: '+ str(w)+ ', '+ str(h))
167
 
        print(u'control: '+ control)
168
 
        test.SetKar(w, h)
169
 
        a, l= test.GetPol()
170
 
        print(u'W, L:      '+ str(a)+ ', '+ str(l))
171