Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
P
pyMKcam
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
machinery
pyMKcam
Commits
bdef19e4
Commit
bdef19e4
authored
Apr 29, 2012
by
Lars Kruse
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
replaced "pnorm(psub(...))" with "pdist(...)"
parent
685ec9f9
Changes
11
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
36 additions
and
33 deletions
+36
-33
Line.py
pycam/Geometry/Line.py
+3
-3
Model.py
pycam/Geometry/Model.py
+2
-2
PointUtils.py
pycam/Geometry/PointUtils.py
+4
-1
Polygon.py
pycam/Geometry/Polygon.py
+12
-12
Triangle.py
pycam/Geometry/Triangle.py
+4
-4
__init__.py
pycam/Geometry/__init__.py
+1
-1
DXFImporter.py
pycam/Importers/DXFImporter.py
+2
-2
PushCutter.py
pycam/PathGenerators/PushCutter.py
+1
-1
__init__.py
pycam/PathGenerators/__init__.py
+2
-2
SupportGrid.py
pycam/Toolpath/SupportGrid.py
+1
-1
__init__.py
pycam/Toolpath/__init__.py
+4
-4
No files found.
pycam/Geometry/Line.py
View file @
bdef19e4
...
...
@@ -157,10 +157,10 @@ class Line(IDGenerator, TransformableContainer):
return
psub
(
self
.
p1
,
pmul
(
v
,
l
))
def
dist_to_point_sq
(
self
,
p
):
return
p
normsq
(
psub
(
p
,
self
.
closes_point
(
p
)
))
return
p
dist_sq
(
p
,
self
.
closes_point
(
p
))
def
dist_to_point
(
self
,
p
):
return
sqrt
(
self
.
dist_to_point_sq
(
p
))
return
pdist
(
p
,
self
.
closes_point
(
p
))
def
is_point_inside
(
self
,
p
):
if
(
p
==
self
.
p1
)
or
(
p
==
self
.
p2
):
...
...
@@ -214,7 +214,7 @@ class Line(IDGenerator, TransformableContainer):
if
self
.
is_point_inside
(
x3
):
candidates
.
append
((
x3
,
pnorm
(
c
)
/
pnorm
(
a
)))
elif
self
.
is_point_inside
(
x4
):
candidates
.
append
((
x4
,
p
norm
(
psub
(
line
.
p2
,
self
.
p1
)
)
/
pnorm
(
a
)))
candidates
.
append
((
x4
,
p
dist
(
line
.
p2
,
self
.
p1
)
/
pnorm
(
a
)))
elif
line
.
is_point_inside
(
x1
):
candidates
.
append
((
x1
,
0
))
elif
line
.
is_point_inside
(
x2
):
...
...
pycam/Geometry/Model.py
View file @
bdef19e4
...
...
@@ -1068,7 +1068,7 @@ class Rectangle(IDGenerator, TransformableContainer):
orders
=
((
p1
,
p2
,
p3
,
p4
),
(
p1
,
p2
,
p4
,
p3
),
(
p1
,
p3
,
p2
,
p4
),
(
p1
,
p3
,
p4
,
p2
),
(
p1
,
p4
,
p2
,
p3
),
(
p1
,
p4
,
p3
,
p2
))
for
order
in
orders
:
if
abs
(
p
norm
(
psub
(
order
[
0
],
order
[
2
]))
-
pnorm
(
psub
(
order
[
1
],
order
[
3
])
))
<
epsilon
:
if
abs
(
p
dist
(
order
[
0
],
order
[
2
])
-
pdist
(
order
[
1
],
order
[
3
]
))
<
epsilon
:
t1
=
Triangle
(
order
[
0
],
order
[
1
],
order
[
2
])
t2
=
Triangle
(
order
[
2
],
order
[
3
],
order
[
0
])
if
t1
.
normal
==
t2
.
normal
==
normal
:
...
...
@@ -1132,7 +1132,7 @@ class Rectangle(IDGenerator, TransformableContainer):
if
len
(
unique_vertices
)
!=
2
:
log
.
error
(
"Invalid number of vertices:
%
s"
%
unique_vertices
)
return
None
if
abs
(
p
norm
(
psub
(
unique_verticies
[
0
],
unique_verticies
[
1
]))
-
pnorm
(
psub
(
shared_vertices
[
0
],
shared_vertices
[
1
])
))
<
epsilon
:
if
abs
(
p
dist
(
unique_verticies
[
0
],
unique_verticies
[
1
])
-
pdist
(
shared_vertices
[
0
],
shared_vertices
[
1
]
))
<
epsilon
:
try
:
return
Rectangle
(
unique_vertices
[
0
],
unique_vertices
[
1
],
shared_vertices
[
0
],
shared_vertices
[
1
],
...
...
pycam/Geometry/PointUtils.py
View file @
bdef19e4
...
...
@@ -33,9 +33,12 @@ def pnormsq(a):
return
pdot
(
a
,
a
)
def
pdist
(
a
,
b
,
axes
=
None
):
return
sqrt
(
pdist_sq
(
a
,
b
,
axes
=
axes
))
def
pdist_sq
(
a
,
b
,
axes
=
None
):
if
axes
is
None
:
axes
=
(
0
,
1
,
2
)
return
s
qrt
(
sum
([(
a
[
index
]
-
b
[
index
])
**
2
for
index
in
axes
])
)
return
s
um
([(
a
[
index
]
-
b
[
index
])
**
2
for
index
in
axes
]
)
def
pcmp
(
a
,
b
):
""" Two points are equal if all dimensions are identical.
...
...
pycam/Geometry/Polygon.py
View file @
bdef19e4
...
...
@@ -71,7 +71,7 @@ class PolygonInTree(IDGenerator):
pass
def
get_cost
(
self
,
other
):
return
p
norm
(
psub
(
other
.
start
,
self
.
end
)
)
return
p
dist
(
other
.
start
,
self
.
end
)
class
PolygonPositionSorter
(
object
):
...
...
@@ -417,9 +417,9 @@ class Polygon(TransformableContainer):
def
get_lengths
(
self
):
result
=
[]
for
index
in
range
(
len
(
self
.
_points
)
-
1
):
result
.
append
(
p
norm
(
psub
(
self
.
_points
[
index
+
1
],
self
.
_points
[
index
])
))
result
.
append
(
p
dist
(
self
.
_points
[
index
+
1
],
self
.
_points
[
index
]
))
if
self
.
is_closed
:
result
.
append
(
p
norm
(
psub
(
self
.
_points
[
0
],
self
.
_points
[
-
1
])
))
result
.
append
(
p
dist
(
self
.
_points
[
0
],
self
.
_points
[
-
1
]
))
return
result
def
get_max_inside_distance
(
self
):
...
...
@@ -427,12 +427,12 @@ class Polygon(TransformableContainer):
"""
if
len
(
self
.
_points
)
<
2
:
return
None
distance
=
p
norm
(
psub
(
self
.
_points
[
1
],
self
.
_points
[
0
])
)
distance
=
p
dist
(
self
.
_points
[
1
],
self
.
_points
[
0
]
)
for
p1
in
self
.
_points
:
for
p2
in
self
.
_points
:
if
p1
is
p2
:
continue
distance
=
max
(
distance
,
p
norm
(
psub
(
p2
,
p1
)
))
distance
=
max
(
distance
,
p
dist
(
p2
,
p1
))
return
distance
def
is_outer
(
self
):
...
...
@@ -601,7 +601,7 @@ class Polygon(TransformableContainer):
max_dist
=
1000
*
epsilon
def
test_point_near
(
p
,
others
):
for
o
in
others
:
if
p
norm
(
psub
(
p
,
o
)
)
<
max_dist
:
if
p
dist
(
p
,
o
)
<
max_dist
:
return
True
return
False
reverse_lines
=
[]
...
...
@@ -645,7 +645,7 @@ class Polygon(TransformableContainer):
# no lines are left
print
"out 2"
return
[]
if
p
norm
(
psub
(
prev_line
.
p2
,
next_line
.
p1
)
)
>
max_dist
:
if
p
dist
(
prev_line
.
p2
,
next_line
.
p1
)
>
max_dist
:
cp
,
dist
=
prev_line
.
get_intersection
(
next_line
)
else
:
cp
=
prev_line
.
p2
...
...
@@ -692,8 +692,8 @@ class Polygon(TransformableContainer):
# maybe we have been here before
if
not
cp
in
split_points
:
split_points
.
append
(
cp
)
elif
(
p
norm
(
psub
(
cp
,
line
.
p1
))
<
max_dist
)
or
(
pnorm
(
psub
(
cp
,
line
.
p2
)
)
<
max_dist
):
if
p
norm
(
psub
(
cp
,
lines
.
p1
))
<
pnorm
(
psub
(
cp
,
line
.
p2
)
):
elif
(
p
dist
(
cp
,
line
.
p1
)
<
max_dist
)
or
(
pdist
(
cp
,
line
.
p2
)
<
max_dist
):
if
p
dist
(
cp
,
lines
.
p1
)
<
pdist
(
cp
,
line
.
p2
):
non_reversed
[
index
]
=
Line
(
cp
,
line
.
p2
)
else
:
non_reversed
[
index
]
=
Line
(
line
.
p1
,
cp
)
...
...
@@ -881,7 +881,7 @@ class Polygon(TransformableContainer):
line1
=
new_group
[
index1
]
line2
=
new_group
[
index2
]
intersection
,
factor
=
line1
.
get_intersection
(
line2
)
if
intersection
and
(
p
norm
(
psub
(
intersection
,
line1
.
p1
))
>
epsilon
)
and
(
pnorm
(
psub
(
intersection
,
line1
.
p2
)
)
>
epsilon
):
if
intersection
and
(
p
dist
(
intersection
,
line1
.
p1
)
>
epsilon
)
and
(
pdist
(
intersection
,
line1
.
p2
)
>
epsilon
):
del
new_group
[
index1
]
new_group
.
insert
(
index1
,
Line
(
line1
.
p1
,
intersection
))
...
...
@@ -895,7 +895,7 @@ class Polygon(TransformableContainer):
if
not
index1
+
1
in
group_starts
:
group_starts
.
append
(
index1
+
1
)
# don't update index2 -> maybe there are other hits
elif
intersection
and
(
p
norm
(
psub
(
intersection
,
line1
.
p1
)
)
<
epsilon
):
elif
intersection
and
(
p
dist
(
intersection
,
line1
.
p1
)
<
epsilon
):
if
not
index1
in
group_starts
:
group_starts
.
append
(
index1
)
index2
+=
1
...
...
@@ -1290,7 +1290,7 @@ class Polygon(TransformableContainer):
for
index
in
range
(
len
(
collisions
)
-
1
):
p1
=
collisions
[
index
][
0
]
p2
=
collisions
[
index
+
1
][
0
]
if
p
norm
(
psub
(
p1
,
p2
)
)
<
epsilon
:
if
p
dist
(
p1
,
p2
)
<
epsilon
:
# ignore zero-length lines
continue
# Use the middle between p1 and p2 to check the
...
...
pycam/Geometry/Triangle.py
View file @
bdef19e4
...
...
@@ -71,12 +71,12 @@ class Triangle(IDGenerator, TransformableContainer):
self
.
plane
=
Plane
(
self
.
center
,
self
.
normal
)
# calculate circumcircle (resulting in radius and middle)
denom
=
pnorm
(
pcross
(
psub
(
self
.
p2
,
self
.
p1
),
psub
(
self
.
p3
,
self
.
p2
)))
self
.
radius
=
(
p
norm
(
psub
(
self
.
p2
,
self
.
p1
))
*
pnorm
(
psub
(
self
.
p3
,
self
.
p2
))
*
pnorm
(
psub
(
self
.
p3
,
self
.
p1
)
))
/
(
2
*
denom
)
self
.
radius
=
(
p
dist
(
self
.
p2
,
self
.
p1
)
*
pdist
(
self
.
p3
,
self
.
p2
)
*
pdist
(
self
.
p3
,
self
.
p1
))
/
(
2
*
denom
)
self
.
radiussq
=
self
.
radius
**
2
denom2
=
2
*
denom
*
denom
alpha
=
p
normsq
(
psub
(
self
.
p3
,
self
.
p2
)
)
*
pdot
(
psub
(
self
.
p1
,
self
.
p2
),
psub
(
self
.
p1
,
self
.
p3
))
/
denom2
beta
=
p
normsq
(
psub
(
self
.
p1
,
self
.
p3
)
)
*
pdot
(
psub
(
self
.
p2
,
self
.
p1
),
psub
(
self
.
p2
,
self
.
p3
))
/
denom2
gamma
=
p
normsq
(
psub
(
self
.
p1
,
self
.
p2
)
)
*
pdot
(
psub
(
self
.
p3
,
self
.
p1
),
psub
(
self
.
p3
,
self
.
p2
))
/
denom2
alpha
=
p
dist_sq
(
self
.
p3
,
self
.
p2
)
*
pdot
(
psub
(
self
.
p1
,
self
.
p2
),
psub
(
self
.
p1
,
self
.
p3
))
/
denom2
beta
=
p
dist_sq
(
self
.
p1
,
self
.
p3
)
*
pdot
(
psub
(
self
.
p2
,
self
.
p1
),
psub
(
self
.
p2
,
self
.
p3
))
/
denom2
gamma
=
p
dist_sq
(
self
.
p1
,
self
.
p2
)
*
pdot
(
psub
(
self
.
p3
,
self
.
p1
),
psub
(
self
.
p3
,
self
.
p2
))
/
denom2
self
.
middle
=
(
self
.
p1
[
0
]
*
alpha
+
self
.
p2
[
0
]
*
beta
+
self
.
p3
[
0
]
*
gamma
,
self
.
p1
[
1
]
*
alpha
+
self
.
p2
[
1
]
*
beta
+
self
.
p3
[
1
]
*
gamma
,
self
.
p1
[
2
]
*
alpha
+
self
.
p2
[
2
]
*
beta
+
self
.
p3
[
2
]
*
gamma
)
...
...
pycam/Geometry/__init__.py
View file @
bdef19e4
...
...
@@ -158,7 +158,7 @@ def get_bezier_lines(points_with_bulge, segments=32):
# point to the end point; a bulge of 0 indicates a straight segment,
# and a bulge of 1 is a semicircle.
alpha
=
2
*
(
abs
(
bulge1
)
+
abs
(
bulge2
))
dist
=
p
norm
(
psub
(
p2
,
p1
)
)
dist
=
p
dist
(
p2
,
p1
)
# calculate the radius of the circumcircle - avoiding divide-by-zero
if
(
abs
(
alpha
)
<
epsilon
)
or
(
abs
(
math
.
pi
-
alpha
)
<
epsilon
):
radius
=
dist
/
2.0
...
...
pycam/Importers/DXFImporter.py
View file @
bdef19e4
...
...
@@ -142,8 +142,8 @@ class DXFParser(object):
current_group
=
[]
groups
.
append
(
current_group
)
def
get_distance_between_groups
(
group1
,
group2
):
forward
=
p
norm
(
psub
(
group1
[
-
1
]
.
p2
,
group2
[
0
]
.
p1
)
)
backward
=
p
norm
(
psub
(
group2
[
-
1
]
.
p2
,
group1
[
0
]
.
p1
)
)
forward
=
p
dist
(
group1
[
-
1
]
.
p2
,
group2
[
0
]
.
p1
)
backward
=
p
dist
(
group2
[
-
1
]
.
p2
,
group1
[
0
]
.
p1
)
return
min
(
forward
,
backward
)
remaining_groups
=
groups
[:]
ordered_groups
=
[]
...
...
pycam/PathGenerators/PushCutter.py
View file @
bdef19e4
...
...
@@ -144,7 +144,7 @@ class PushCutter(object):
for
line
in
layer_grid
:
p1
,
p2
=
line
# calculate the required calculation depth (recursion)
distance
=
p
norm
(
psub
(
p2
,
p1
)
)
distance
=
p
dist
(
p2
,
p1
)
# TODO: accessing cutter.radius here is slightly ugly
depth
=
math
.
log
(
accuracy
*
distance
/
cutter
.
radius
)
/
math
.
log
(
2
)
depth
=
min
(
max
(
ceil
(
depth
),
4
),
max_depth
)
...
...
pycam/PathGenerators/__init__.py
View file @
bdef19e4
...
...
@@ -66,7 +66,7 @@ def get_free_paths_triangles(models, cutter, p1, p2, return_triangles=False):
backward
=
pnormalized
(
psub
(
p1
,
p2
))
forward
=
pnormalized
(
psub
(
p2
,
p1
))
xyz_dist
=
p
norm
(
psub
(
p2
,
p1
)
)
xyz_dist
=
p
dist
(
p2
,
p1
)
minx
=
min
(
p1
[
0
],
p2
[
0
])
maxx
=
max
(
p1
[
0
],
p2
[
0
])
...
...
@@ -252,7 +252,7 @@ def get_max_height_triangles(model, cutter, x, y, minz, maxz):
def
_check_deviance_of_adjacent_points
(
p1
,
p2
,
p3
,
min_distance
):
straight
=
psub
(
p3
,
p1
)
added
=
p
norm
(
psub
(
p2
,
p1
))
+
pnorm
(
psub
(
p3
,
p2
)
)
added
=
p
dist
(
p2
,
p1
)
+
pdist
(
p3
,
p2
)
# compare only the x/y distance of p1 and p3 with min_distance
if
straight
[
0
]
**
2
+
straight
[
1
]
**
2
<
min_distance
**
2
:
# the points are too close together
...
...
pycam/Toolpath/SupportGrid.py
View file @
bdef19e4
...
...
@@ -272,7 +272,7 @@ def _get_edge_bridges(polygon, z_plane, min_bridges, average_distance,
avoid_distance
):
def
is_near_list
(
point_list
,
point
,
distance
):
for
p
in
point_list
:
if
p
norm
(
psub
(
p
,
point
)
)
<=
distance
:
if
p
dist
(
p
,
point
)
<=
distance
:
return
True
return
False
lines
=
polygon
.
get_lines
()
...
...
pycam/Toolpath/__init__.py
View file @
bdef19e4
...
...
@@ -176,7 +176,7 @@ class Toolpath(object):
self
.
last_pos
=
new_position
return
True
else
:
distance
=
p
norm
(
psub
(
new_position
,
self
.
last_pos
)
)
distance
=
p
dist
(
new_position
,
self
.
last_pos
)
if
self
.
moved_distance
+
distance
>
self
.
max_movement
:
partial
=
(
self
.
max_movement
-
self
.
moved_distance
)
/
\
distance
...
...
@@ -207,7 +207,7 @@ class Toolpath(object):
if
((
abs
(
p_last
[
0
]
-
p_next
[
0
])
>
epsilon
)
or
(
abs
(
p_last
[
1
]
-
p_next
[
1
])
>
epsilon
)):
# Draw the connection between the last and the next path.
# Respect the safety height.
if
(
abs
(
p_last
[
2
]
-
p_next
[
2
])
>
epsilon
)
or
(
p
norm
(
psub
(
p_last
,
p_next
)
)
>
self
.
_max_safe_distance
+
epsilon
):
if
(
abs
(
p_last
[
2
]
-
p_next
[
2
])
>
epsilon
)
or
(
p
dist
(
p_last
,
p_next
)
>
self
.
_max_safe_distance
+
epsilon
):
# The distance between these two points is too far.
# This condition helps to prevent moves up/down for
# adjacent lines.
...
...
@@ -324,7 +324,7 @@ class Toolpath(object):
lastp
=
outpaths
[
-
1
][
0
][
-
1
]
working_path
.
append
((
path
[
0
][
0
],
path
[
0
][
1
],
safety_height
))
if
((
abs
(
lastp
[
0
]
-
path
[
0
][
0
])
>
epsilon
)
or
(
abs
(
lastp
[
1
]
-
path
[
0
][
1
])
>
epsilon
)):
if
(
abs
(
lastp
[
2
]
-
path
[
0
][
2
])
>
epsilon
)
or
(
p
norm
(
psub
(
lastp
,
path
[
0
])
)
>
self
.
_max_safe_distance
+
epsilon
):
if
(
abs
(
lastp
[
2
]
-
path
[
0
][
2
])
>
epsilon
)
or
(
p
dist
(
lastp
,
path
[
0
]
)
>
self
.
_max_safe_distance
+
epsilon
):
outpaths
.
append
((
tuple
([
x
[
0
]
for
x
in
groupby
(
working_path
)]),
True
))
else
:
working_path
.
append
((
0
,
0
,
0
))
...
...
@@ -373,7 +373,7 @@ class Toolpath(object):
for
move_type
,
args
in
self
.
get_basic_moves
():
if
move_type
in
(
MOVE_STRAIGHT
,
MOVE_STRAIGHT_RAPID
):
if
not
current_position
is
None
:
result
+=
p
norm
(
psub
(
args
,
current_position
)
)
result
+=
p
dist
(
args
,
current_position
)
current_position
=
args
return
result
def
get_basic_moves
(
self
,
reset_cache
=
False
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment