New AMF-to-STL and STL-to-AMF converters

This commit is contained in:
Alessandro Ranellucci 2012-02-19 15:45:27 +01:00
parent 79ebb13bdb
commit 776d985b26
6 changed files with 170 additions and 4 deletions

View file

@ -19,7 +19,7 @@ our @EXPORT_OK = qw(
polygon_remove_acute_vertices polygon_remove_parallel_continuous_edges
shortest_path collinear scale unscale merge_collinear_lines
rad2deg_dir bounding_box_center line_intersects_any
polyline_remove_short_segments
polyline_remove_short_segments normal triangle_normal
);
use Slic3r::Geometry::DouglasPeucker qw(Douglas_Peucker);
@ -414,6 +414,25 @@ sub subtract_vectors {
return [ $line2->[X] - $line1->[X], $line2->[Y] - $line1->[Y] ];
}
sub normal {
my ($line1, $line2) = @_;
return [
($line1->[Y] * $line2->[Z]) - ($line1->[Z] * $line2->[Y]),
-($line2->[Z] * $line1->[X]) + ($line2->[X] * $line1->[Z]),
($line1->[X] * $line2->[Y]) - ($line1->[Y] * $line2->[X]),
];
}
sub triangle_normal {
my ($v1, $v2, $v3) = @_;
my $u = [ map +($v2->[$_] - $v1->[$_]), (X,Y,Z) ];
my $v = [ map +($v3->[$_] - $v1->[$_]), (X,Y,Z) ];
return normal($u, $v);
}
# 2D dot product
sub dot {
my ($u, $v) = @_;