bool Comb::lineSegmentCollidesWithBoundary(Point startPoint, Point endPoint) { Point diff = endPoint - startPoint; transformation_matrix = PointMatrix(diff); transformed_startPoint = transformation_matrix.apply(startPoint); transformed_endPoint = transformation_matrix.apply(endPoint); for(unsigned int n=0; n<boundary.size(); n++) { if (boundary[n].size() < 1) continue; Point p0 = transformation_matrix.apply(boundary[n][boundary[n].size()-1]); for(unsigned int i=0; i<boundary[n].size(); i++) { Point p1 = transformation_matrix.apply(boundary[n][i]); if ((p0.Y > transformed_startPoint.Y && p1.Y < transformed_startPoint.Y) || (p1.Y > transformed_startPoint.Y && p0.Y < transformed_startPoint.Y)) { int64_t x = p0.X + (p1.X - p0.X) * (transformed_startPoint.Y - p0.Y) / (p1.Y - p0.Y); if (x > transformed_startPoint.X && x < transformed_endPoint.X) return true; } p0 = p1; } } return false; }
bool LinePolygonsCrossings::lineSegmentCollidesWithBoundary() { Point diff = endPoint - startPoint; transformation_matrix = PointMatrix(diff); transformed_startPoint = transformation_matrix.apply(startPoint); transformed_endPoint = transformation_matrix.apply(endPoint); for(PolygonRef poly : boundary) { Point p0 = transformation_matrix.apply(poly.back()); for(Point p1_ : poly) { Point p1 = transformation_matrix.apply(p1_); if ((p0.Y > transformed_startPoint.Y && p1.Y < transformed_startPoint.Y) || (p1.Y > transformed_startPoint.Y && p0.Y < transformed_startPoint.Y)) { int64_t x = p0.X + (p1.X - p0.X) * (transformed_startPoint.Y - p0.Y) / (p1.Y - p0.Y); if (x > transformed_startPoint.X && x < transformed_endPoint.X) return true; } p0 = p1; } } return false; }
bool Comb::collisionTest(Point startPoint, Point endPoint) { Point diff = endPoint - startPoint; matrix = PointMatrix(diff); sp = matrix.apply(startPoint); ep = matrix.apply(endPoint); for(unsigned int n=0; n<boundery.size(); n++) { if (boundery[n].size() < 1) continue; Point p0 = matrix.apply(boundery[n][boundery[n].size()-1]); for(unsigned int i=0; i<boundery[n].size(); i++) { Point p1 = matrix.apply(boundery[n][i]); if ((p0.Y > sp.Y && p1.Y < sp.Y) || (p1.Y > sp.Y && p0.Y < sp.Y)) { int64_t x = p0.X + (p1.X - p0.X) * (sp.Y - p0.Y) / (p1.Y - p0.Y); if (x > sp.X && x < ep.X) return true; } p0 = p1; } } return false; }
bool polygonCollidesWithlineSegment(Polygons& polys, Point& startPoint, Point& endPoint) { Point diff = endPoint - startPoint; PointMatrix transformation_matrix = PointMatrix(diff); Point transformed_startPoint = transformation_matrix.apply(startPoint); Point transformed_endPoint = transformation_matrix.apply(endPoint); return polygonCollidesWithlineSegment(polys, transformed_startPoint, transformed_endPoint, transformation_matrix); }
void SubDivCube::precomputeOctree(SliceMeshStorage& mesh) { radius_addition = mesh.getSettingInMicrons("sub_div_rad_add"); double infill_angle = M_PI / 4.0; coord_t furthest_dist_from_origin = std::sqrt(square(mesh.getSettingInMicrons("machine_height")) + square(mesh.getSettingInMicrons("machine_depth") / 2) + square(mesh.getSettingInMicrons("machine_width") / 2)); coord_t max_side_length = furthest_dist_from_origin * 2; int curr_recursion_depth = 0; const int64_t infill_line_distance = mesh.getSettingInMicrons("infill_line_distance"); if (infill_line_distance > 0) { for (int64_t curr_side_length = infill_line_distance * 2; curr_side_length < max_side_length * 2; curr_side_length *= 2) { cube_properties_per_recursion_step.emplace_back(); CubeProperties& cube_properties_here = cube_properties_per_recursion_step.back(); cube_properties_here.side_length = curr_side_length; cube_properties_here.height = sqrt(3) * curr_side_length; cube_properties_here.square_height = sqrt(2) * curr_side_length; cube_properties_here.max_draw_z_diff = ONE_OVER_SQRT_3 * curr_side_length; cube_properties_here.max_line_offset = ONE_OVER_SQRT_6 * curr_side_length; curr_recursion_depth++; } } Point3 center(0, 0, 0); Point3Matrix tilt; // rotation matrix to get from axis aligned cubes to cubes standing on their tip // The Z axis is transformed to go in positive Y direction // // cross section in a horizontal plane horizontal plane showing // looking down at the origin O positive X and positive Y // Z . // /:\ Y . // / : \ ^ . // / : \ | . // / .O. \ | . // /.~' '~.\ O---->X . // X """"""""""" Y . tilt.matrix[0] = -ONE_OVER_SQRT_2; tilt.matrix[1] = ONE_OVER_SQRT_2; tilt.matrix[2] = 0; tilt.matrix[3] = -ONE_OVER_SQRT_6; tilt.matrix[4] = -ONE_OVER_SQRT_6; tilt.matrix[5] = SQRT_TWO_THIRD ; tilt.matrix[6] = ONE_OVER_SQRT_3; tilt.matrix[7] = ONE_OVER_SQRT_3; tilt.matrix[8] = ONE_OVER_SQRT_3; infill_rotation_matrix = PointMatrix(infill_angle); Point3Matrix infill_angle_mat(infill_rotation_matrix); rotation_matrix = infill_angle_mat.compose(tilt); mesh.base_subdiv_cube = new SubDivCube(mesh, center, curr_recursion_depth - 1); }