Skip to content

Commit

Permalink
Use cosine formula instead of length formula
Browse files Browse the repository at this point in the history
  • Loading branch information
eyal0 committed Jun 17, 2020
1 parent a3c09b8 commit 242962f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
12 changes: 9 additions & 3 deletions eulerian_paths.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,11 +200,17 @@ class eulerian_paths {
// This must be reversed.
p2 = paths[option.second.first].first[paths[option.second.first].first.size()-2];
}
auto length_p0_p1 = bg::distance(p0, p1);
auto length_p1_p2 = bg::distance(p1, p2);
auto delta_x = (p1.x() - p0.x())/length_p0_p1 + (p2.x() - p1.x())/length_p1_p2;
/*auto delta_x = (p1.x() - p0.x())/length_p0_p1 + (p2.x() - p1.x())/length_p1_p2;
auto delta_y = (p1.y() - p0.y())/length_p0_p1 + (p2.y() - p1.y())/length_p1_p2;
return (delta_x * delta_x + delta_y * delta_y); // No need to sqrt, this is comparable.
*/
auto delta_x10 = p0.x() - p1.x();
auto delta_y10 = p0.y() - p1.y();
auto delta_x12 = p2.x() - p1.x();
auto delta_y12 = p2.y() - p1.y();
auto length_product = sqrt((delta_x10*delta_x10 + delta_y10*delta_y10) * (delta_x12*delta_x12 + delta_y12*delta_y12));
auto dot_product = (delta_x10*delta_x12) + (delta_y10*delta_y12);
return -dot_product/length_product;
}

double path_score(const linestring_t&,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ G01 X-10.43250 Y10.43250
G01 X-10.43250 Y-0.43250
G01 X0.43250 Y-0.43250
G01 X0.38250 Y-0.38250
G01 X0.38250 Y10.38250
G01 X-10.38250 Y10.38250
G01 X-10.38250 Y-0.38250
G01 X-10.38250 Y10.38250
G01 X0.38250 Y10.38250
G01 X0.38250 Y-0.38250
G04 P0 ( dwell for no time -- G64 should not smooth over this point )
G00 Z0.08000 ( retract )
Expand Down

0 comments on commit 242962f

Please sign in to comment.