Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/FormerLurker/ArcWelderLib.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFormerLurker <hochgebe@gmail.com>2020-11-20 20:17:12 +0300
committerFormerLurker <hochgebe@gmail.com>2020-11-20 20:17:12 +0300
commit995ec6d5b35cf8ae23dabb74065fdafdcc843740 (patch)
tree83b947814b49f057625fd11ff23c9d6c82654977 /ArcWelder/segmented_shape.cpp
parent0f57a03f82a555a9b6d3afdfb133457c72455d54 (diff)
Add test spiral vase support.
Diffstat (limited to 'ArcWelder/segmented_shape.cpp')
-rw-r--r--ArcWelder/segmented_shape.cpp57
1 files changed, 46 insertions, 11 deletions
diff --git a/ArcWelder/segmented_shape.cpp b/ArcWelder/segmented_shape.cpp
index 4a489da..170b1df 100644
--- a/ArcWelder/segmented_shape.cpp
+++ b/ArcWelder/segmented_shape.cpp
@@ -197,7 +197,7 @@ bool circle::try_create_circle(const point& p1, const point& p2, const point& p3
return true;
}
-bool circle::try_create_circle(const array_list<point>& points, const double max_radius, const double resolution_mm, circle& new_circle, bool check_middle_only)
+bool circle::try_create_circle(const array_list<point>& points, const double max_radius, const double resolution_mm, const int xyz_precision, bool allow_z_axis_changes, bool check_middle_only, circle& new_circle)
{
int middle_index = points.count() / 2;
int check_index;
@@ -209,7 +209,7 @@ bool circle::try_create_circle(const array_list<point>& points, const double max
// Check the index
if (circle::try_create_circle(points[0], points[check_index], points[points.count() - 1], max_radius, new_circle))
{
- if (!new_circle.is_over_deviation(points, resolution_mm))
+ if (!new_circle.is_over_deviation(points, resolution_mm, xyz_precision, allow_z_axis_changes))
{
return true;
}
@@ -268,20 +268,40 @@ point circle::get_closest_point(const point& p) const
return point(px, py, pz, 0);
}
-bool circle::is_over_deviation(const array_list<point>& points, const double resolution_mm)
+bool circle::is_over_deviation(const array_list<point>& points, const double resolution_mm, const int xyz_precision, const bool allow_z_axis_changes)
{
+ // We need to ensure that the Z steps are constand per linear travel unit
+ double z_step_per_distance = 0;
// Skip the first and last points since they will fit perfectly.
+ // UNLESS allow z changes is set to true, then we need to do some different stuff
+ int final_index = points.count() - 1 + (allow_z_axis_changes ? 1 : 0);
for (int index = 1; index < points.count() - 1; index++)
{
// Make sure the length from the center of our circle to the test point is
// at or below our max distance.
- double distance = utilities::get_cartesian_distance(points[index].x, points[index].y, center.x, center.y);
+ double distance = distance = utilities::get_cartesian_distance(points[index].x, points[index].y, center.x, center.y);
+ if (allow_z_axis_changes) {
+ double z1 = points[index - 1].z;
+ double z2 = points[index].z;
+
+ double current_z_stepper_distance = (z2 - z1)/distance;
+ if (z_step_per_distance == 0){
+ z_step_per_distance = current_z_stepper_distance;
+ }
+ if (!utilities::is_equal(z_step_per_distance, current_z_stepper_distance, std::pow(10, -1.0 * xyz_precision)))
+ {
+ // The z step is uneven, can't create arc
+ return true;
+ }
+
+ }
+
if (std::abs(distance - radius) > resolution_mm)
{
return true;
}
}
-
+
// Check the point perpendicular from the segment to the circle's center, if any such point exists
for (int index = 0; index < points.count() - 1; index++)
{
@@ -310,7 +330,8 @@ bool arc::try_create_arc(
arc& target_arc,
double approximate_length,
double resolution,
- double path_tolerance_percent)
+ double path_tolerance_percent,
+ bool allow_z_axis_changes)
{
double polar_start_theta = c.get_polar_radians(start_point);
double polar_mid_theta = c.get_polar_radians(mid_point);
@@ -383,6 +404,17 @@ bool arc::try_create_arc(
arc_length = test_arc_length;
direction = direction == 1 ? 2 : 1;
}
+
+ if (allow_z_axis_changes)
+ {
+ // Ensure the perimeter of the arc is less than that of a full circle
+ double perimeter = c.radius * 2.0 * PI_DOUBLE;
+ if (perimeter <= approximate_length) {
+ return false;
+ }
+
+ }
+
if(direction == 2)
angle_radians *= -1.0;
@@ -407,10 +439,11 @@ bool arc::try_create_arc(
arc& target_arc,
double approximate_length,
double resolution,
- double path_tolerance_percent)
+ double path_tolerance_percent,
+ bool allow_z_axis_changes)
{
int mid_point_index = ((points.count() - 2) / 2) + 1;
- return arc::try_create_arc(c, points[0], points[mid_point_index], points[points.count() - 1], target_arc, approximate_length, resolution, path_tolerance_percent);
+ return arc::try_create_arc(c, points[0], points[mid_point_index], points[points.count() - 1], target_arc, approximate_length, resolution, path_tolerance_percent, allow_z_axis_changes);
}
bool arc::try_create_arc(
const array_list<point>& points,
@@ -418,13 +451,15 @@ bool arc::try_create_arc(
double approximate_length,
double max_radius_mm,
double resolution_mm,
- double path_tolerance_percent)
+ double path_tolerance_percent,
+ int xyz_precision,
+ bool allow_z_axis_changes)
{
circle test_circle;
- if (circle::try_create_circle(points, max_radius_mm, resolution_mm, test_circle, false))
+ if (circle::try_create_circle(points, max_radius_mm, resolution_mm, xyz_precision, allow_z_axis_changes, false, test_circle))
{
int mid_point_index = ((points.count() - 2) / 2) + 1;
- return arc::try_create_arc(test_circle, points[0], points[mid_point_index], points[points.count()-1], target_arc, approximate_length, resolution_mm, path_tolerance_percent);
+ return arc::try_create_arc(test_circle, points[0], points[mid_point_index], points[points.count()-1], target_arc, approximate_length, resolution_mm, path_tolerance_percent, allow_z_axis_changes);
}
return false;
}