2
# -*- coding: utf-8 -*-
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
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.
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.
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/>.
26
def __init__(self, options):
39
# integer: number of decimal places
40
self.__dps= options.GetDezPlcs()
42
def SetKar(self, width, height):
43
# set width and height: float
44
self.__width= float(width)
45
self.__height= float(height)
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
57
# get width and height from angle and length: float
59
return ((self.__width, self.__height))
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)
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:
74
self.__length= self.__height
75
elif self.__width== 0 and self.__height< 0:
77
self.__length= abs(self.__height)
78
elif self.__width> 0 and self.__height== 0:
80
self.__length= self.__width
81
elif self.__width< 0 and self.__height== 0:
83
self.__length= abs(self.__width)
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:
91
elif self.__height< 0 and self.__width< 0:
93
elif self.__height<0 and self.__width> 0:
95
self.__angle= round(a, self.__dps)
96
self.__length= round(l, self.__dps)
97
return (self.__angle, self.__length)
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)
106
if __name__== '__main__':
107
from lrzoptions import LorzeOptions
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'),
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'),
124
(-159, 25, '-23.339510662, -8.959198739'),
125
(-180, 35, '-35, 0'),
126
(-218, 37, '-29.156397883, 22.779474587'),
128
(-289, 27, '8.79034017, 25.529001541'),
130
(-489, 43, '-27.060776815, -33.417276343')]:
132
print(u'W, L: '+str(a)+ ', '+ str(l))
133
print(u'control: '+ control)
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'),
141
(-58, 56, '136.005086005, 80.622577483'),
143
(-45, -39, '220.91438322, 59.548299724'),
145
(89, -28, '342.536073108, 93.300589494'),
147
(113.684312408, 243.796794713, '65, 269'),
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'),
155
(246.809064857, 529.283747629, '65, 584'),
156
(35.507086366, -47.119495093, '307, 59'),
158
(-23.339510662, -8.959198739, '201, 25'),
160
(-29.156397883, 22.779474587, '142, 37'),
162
(8.79034017, 25.529001541, '71, 27'),
164
(-27.060776815, -33.417276343, '231, 43')]:
166
print(u'B, H: '+ str(w)+ ', '+ str(h))
167
print(u'control: '+ control)
170
print(u'W, L: '+ str(a)+ ', '+ str(l))