def draw_reactions(self, scale=1.0, tol=1e-3, color=None, identifier='is_anchor'): color = color or '#00ff00' reactions = [] for key, attr in self.datastructure.vertices(True): if not attr[identifier]: continue r = self.datastructure.get_vertex_attributes(key, ('rx', 'ry')) l = length_vector_xy(r) if l < tol: continue sp = self.datastructure.get_vertex_attributes(key, 'xy') ep = sp[0] - scale * r[0], sp[1] - scale * r[1] reactions.append({ 'start': sp, 'end': ep, 'color': color, 'arrow': 'end', 'width': 2.0, 'text': '{:.1f}'.format(l) }) draw_xlines_xy(reactions, self.axes)
def get_distance(self, point): """ single point distance function """ if not isinstance(point, Point): point = Point(*point) point.transform(self.inversetransform) dxy = length_vector_xy(point) # distance_point_point_xy(self.torus.center, point) d2 = sqrt((dxy - self.torus.radius_axis)**2 + point.z**2) return d2 - self.torus.radius_pipe
def get_distance(self, point): """ single point distance function """ if not isinstance(point, Point): point = Point(*point) point.transform(self.inversetransform) dxy = length_vector_xy( point) # distance_point_point_xy(self.cylinder.center, point) d = dxy - self.cylinder.radius d = max(d, abs(point.z) - self.cylinder.height / 2.0) return d
def get_distance(self, point): """ single point distance function """ if not isinstance(point, Point): point = Point(*point) frame = Frame.from_plane(self.cone.plane) m = matrix_from_frame(frame) mi = matrix_inverse(m) point.transform(mi) dxy = length_vector_xy(point) a = 1.1 c = [sin(a), cos(a)] # dot product d = sum( [i * j for (i, j) in zip(c, [dxy, point.z - self.cone.height])]) return d
def intersection_circle_circle_xy(circle1, circle2): """Calculates the intersection points of two circles in 2d lying in the XY plane. Parameters ---------- circle1 : tuple center, radius of the first circle in the xy plane. circle2 : tuple center, radius of the second circle in the xy plane. Returns ------- points : list of tuples the intersection points if there are any None if there are no intersection points """ p1, r1 = circle1[0], circle1[1] p2, r2 = circle2[0], circle2[1] d = length_vector_xy(subtract_vectors_xy(p2, p1)) if d > r1 + r2: return None if d < fabs(r1 - r2): return None if (d == 0) and (r1 == r2): return None a = (r1 * r1 - r2 * r2 + d * d) / (2 * d) h = (r1 * r1 - a * a)**0.5 cx2 = p1[0] + a * (p2[0] - p1[0]) / d cy2 = p1[1] + a * (p2[1] - p1[1]) / d i1 = ((cx2 + h * (p2[1] - p1[1]) / d), (cy2 - h * (p2[0] - p1[0]) / d), 0) i2 = ((cx2 - h * (p2[1] - p1[1]) / d), (cy2 + h * (p2[0] - p1[0]) / d), 0) return i1, i2
def intersection_circle_circle_xy(circle1, circle2): """Calculates the intersection points of two circles in 2d lying in the XY plane. Parameters ---------- circle1 : [plane, float] | :class:`compas.geometry.Circle` Circle defined by a point, with at least XY coordinates, and a radius. circle2 : [plane, float] | :class:`compas.geometry.Circle` Circle defined by a point, with at least XY coordinates, and a radius. Returns ------- tuple[[float, float, float], [float, float, float]] | None The intersection points if there are any. If the circles are tangent to each other, the two intersection points are identical. None otherwise. """ p1, r1 = circle1[0], circle1[1] p2, r2 = circle2[0], circle2[1] d = length_vector_xy(subtract_vectors_xy(p2, p1)) if d > r1 + r2: return None if d < fabs(r1 - r2): return None if (d == 0) and (r1 == r2): return None a = (r1 * r1 - r2 * r2 + d * d) / (2 * d) h = (r1 * r1 - a * a)**0.5 cx2 = p1[0] + a * (p2[0] - p1[0]) / d cy2 = p1[1] + a * (p2[1] - p1[1]) / d i1 = ((cx2 + h * (p2[1] - p1[1]) / d), (cy2 - h * (p2[0] - p1[0]) / d), 0) i2 = ((cx2 - h * (p2[1] - p1[1]) / d), (cy2 + h * (p2[0] - p1[0]) / d), 0) return i1, i2
def draw_loads(self, scale=1.0, tol=1e-3, color=None): color = color or '#00ff00' loads = [] for key in self.datastructure.vertices(): p = self.datastructure.get_vertex_attributes(key, ('px', 'py')) l = length_vector_xy(p) if l < tol: continue sp = self.datastructure.get_vertex_attributes(key, 'xy') ep = sp[0] + scale * p[0], sp[1] + scale * p[1] loads.append({ 'start': sp, 'end': ep, 'color': color, 'arrow': 'end', 'width': 2.0, 'text': '{:.1f}'.format(l) }) draw_xlines_xy(loads, self.axes)
def get_distance(self, point): """ single point distance function Parameters ---------- point: :class:`compas.geometry.Point` The point in R<sup>3</sup> space to query for it's distance. Returns ------- float The distance from the query point to the surface of the object. """ if not isinstance(point, Point): point = Point(*point) point.transform(self.inversedmatrix) f = (point.z + self.cone.height / 2) / self.cone.height temprad = self.cone.radius - f * self.cone.radius dxy = length_vector_xy(point) - temprad return max(dxy, abs(point.z) - self.cone.height / 2)