def face_curvature(self, fkey): """Dimensionless face curvature. Face curvature is defined as the maximum face vertex deviation from the best-fit plane of the face vertices divided by the average lengths of the face vertices to the face centroid. Parameters ---------- fkey : int The face key. Returns ------- float The dimensionless curvature. """ vertices = self.face_vertices(fkey) points = [self.vertex_coordinates(key) for key in vertices] centroid = self.face_centroid(fkey) plane = bestfit_plane(points) max_deviation = max( [distance_point_plane(point, plane) for point in points]) average_distances = vector_average( [distance_point_point(point, centroid) for point in points]) return max_deviation / average_distances
def calc_correction_vector_tip(pt_new, base_pts): """Computing correction vector to meet the distance threshold. return vector P-P_c (figure below). .. image:: ../images/vertex_correction_to_top_connection.png :scale: 80 % :align: center Parameters ---------- pt_new : [type] [description] base_pts : list of three points contact base points for the base bars """ assert len(base_pts) == 3 vec_x = normalize_vector(vector_from_points(base_pts[0], base_pts[1])) vec_y = normalize_vector(vector_from_points(base_pts[0], base_pts[2])) vec_z = normalize_vector(cross_vectors(vec_x, vec_y)) pl_test = (base_pts[0], vec_z) dist_p = distance_point_plane(pt_new, pl_test) pt_proj = project_point_plane(pt_new, pl_test) if dist_p < NODE_CORRECTION_TOP_DISTANCE: vec_m = scale_vector(normalize_vector(vector_from_points(pt_proj, pt_new)), NODE_CORRECTION_TOP_DISTANCE) pt_n = add_vectors(pt_proj, vec_m) else: pt_n = None return pt_n
def Get_distancefromBeamYZFrame(self,placed_point): """Computes the distance from selected point to Beam YZ_Plane(face_id = 0) Parameters: ---------- BeamRef: Beam Object placed_point: Point3d Return: ------ distance (double) """ YZ_Plane = self.face_plane(0) dist = distance_point_plane(placed_point,YZ_Plane) return dist
def distance_to_plane(self, plane): """Compute the distance to a plane. Parameters ---------- plane : :class:`compas.geometry.Plane` or tuple of point and normal The plane. Returns ------- float The distance. Examples -------- >>> from compas.geometry import Plane >>> from compas.geometry import Vector >>> point = Point(0.0, 0.0, 0.0) >>> plane = Plane(Point(1.0, 0.0, 0.0), Vector(1.0, 0.0, 0.0)) >>> point.distance_to_plane(plane) 1.0 """ return distance_point_plane(self, plane)
def distance_to_plane(self, plane): return distance_point_plane(self, plane)
data['overhang'] = Vector(0.0, 0.0, 1.0).dot(face_normal) # face looking towards the positive y axis - Boolean value (per face) mesh.update_default_face_attributes({'positive_y_axis': False}) for f_key, data in mesh.faces(data=True): face_normal = mesh.face_normal(f_key, unitized=True) is_positive_y = Vector(0.0, 1.0, 0.0).dot(face_normal) > 0 # boolean value data['positive_y_axis'] = is_positive_y # distance from plane - Scalar value (per vertex) mesh.update_default_vertex_attributes({'dist_from_plane': 0.0}) plane = (Point(0.0, 0.0, -30.0), Vector(0.0, 0.5, 0.5)) for v_key, data in mesh.vertices(data=True): v_coord = mesh.vertex_coordinates(v_key, axes='xyz') data['dist_from_plane'] = distance_point_plane(v_coord, plane) # direction towards point - Vector value (per vertex) mesh.update_default_vertex_attributes({'direction_to_pt': 0.0}) pt = Point(4.0, 1.0, 0.0) for v_key, data in mesh.vertices(data=True): v_coord = mesh.vertex_coordinates(v_key, axes='xyz') data['direction_to_pt'] = np.array( normalize_vector(Vector.from_start_end(v_coord, pt))) # --------------- Slice mesh slicer = PlanarSlicer(mesh, slicer_type="default", layer_height=5.0) slicer.slice_model() simplify_paths_rdp_igl(slicer, threshold=1.0) slicer_utils.save_to_json(slicer.to_data(), OUTPUT_PATH, 'slicer_data.json')