193 return len(self.vertices) |
193 return len(self.vertices) |
194 @property |
194 @property |
195 def perimeter_lines(self): |
195 def perimeter_lines(self): |
196 for v1, v2 in pairs(self.vertices): |
196 for v1, v2 in pairs(self.vertices): |
197 yield LineSegment(v1, v2) |
197 yield LineSegment(v1, v2) |
198 @property |
198 def angle_cosines(self): |
199 def angles(self): |
199 from math import isclose |
200 from math import acos, isclose |
|
201 for v1, v2, v3 in pairs(self.vertices, count = 3): |
200 for v1, v2, v3 in pairs(self.vertices, count = 3): |
202 vec1 = (position_vector(v3) - position_vector(v2)).normalized() |
201 vec1 = (position_vector(v3) - position_vector(v2)).normalized() |
203 vec2 = (position_vector(v1) - position_vector(v2)).normalized() |
202 vec2 = (position_vector(v1) - position_vector(v2)).normalized() |
204 if not isclose(vec1.length(), 0) and not isclose(vec2.length(), 0): |
203 if not isclose(vec1.length(), 0) and not isclose(vec2.length(), 0): |
205 cosine = dot_product(vec1, vec2) / vec1.length() / vec2.length() |
204 cosine = dot_product(vec1, vec2) / vec1.length() / vec2.length() |
206 yield acos(cosine) |
205 yield cosine |
207 @property |
206 else: |
208 def smallest_angle(self): |
207 yield 1 # cos(0) |
209 return min( |
|
210 angle_magnitude_key(angle) |
|
211 for angle in self.angles) |
|
212 @property |
208 @property |
213 def hairline_ratio(self): |
209 def hairline_ratio(self): |
214 lengths = [line.length for line in self.perimeter_lines] |
210 lengths = [line.length for line in self.perimeter_lines] |
215 return max(lengths) / min(lengths) |
211 return max(lengths) / min(lengths) |
216 |
212 |