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
73cb1bb0
Commit
73cb1bb0
authored
Mar 24, 2012
by
Whitham D. Reeve II
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Removed old commented out code and converted PolygonExtractor.py to new Point tuple style.
parent
d45b6dcb
Changes
10
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
90 additions
and
270 deletions
+90
-270
Letters.py
pycam/Geometry/Letters.py
+0
-4
Line.py
pycam/Geometry/Line.py
+0
-19
Model.py
pycam/Geometry/Model.py
+0
-9
Plane.py
pycam/Geometry/Plane.py
+0
-5
PointKdtree.py
pycam/Geometry/PointKdtree.py
+0
-1
Polygon.py
pycam/Geometry/Polygon.py
+0
-37
PolygonExtractor.py
pycam/Geometry/PolygonExtractor.py
+85
-85
Triangle.py
pycam/Geometry/Triangle.py
+5
-31
__init__.py
pycam/Geometry/__init__.py
+0
-21
intersection.py
pycam/Geometry/intersection.py
+0
-58
No files found.
pycam/Geometry/Letters.py
View file @
73cb1bb0
...
@@ -119,7 +119,6 @@ class Charset(object):
...
@@ -119,7 +119,6 @@ class Charset(object):
for
character
in
line
:
for
character
in
line
:
if
character
==
" "
:
if
character
==
" "
:
base
=
padd
(
base
,
(
word_spacing
,
0
,
0
))
base
=
padd
(
base
,
(
word_spacing
,
0
,
0
))
#base = base.add(Point(word_spacing, 0, 0))
elif
character
in
self
.
letters
.
keys
():
elif
character
in
self
.
letters
.
keys
():
charset_letter
=
self
.
letters
[
character
]
charset_letter
=
self
.
letters
[
character
]
new_model
=
ContourModel
()
new_model
=
ContourModel
()
...
@@ -133,14 +132,11 @@ class Charset(object):
...
@@ -133,14 +132,11 @@ class Charset(object):
line_height
=
max
(
line_height
,
charset_letter
.
maxy
())
line_height
=
max
(
line_height
,
charset_letter
.
maxy
())
# shift the base position
# shift the base position
base
=
padd
(
base
,
(
charset_letter
.
maxx
()
+
letter_spacing
,
0
,
0
))
base
=
padd
(
base
,
(
charset_letter
.
maxx
()
+
letter_spacing
,
0
,
0
))
#base = base.add((charset_letter.maxx() + letter_spacing, 0, 0))
else
:
else
:
# unknown character - add a small whitespace
# unknown character - add a small whitespace
base
=
padd
(
base
,
(
letter_spacing
,
0
,
0
))
base
=
padd
(
base
,
(
letter_spacing
,
0
,
0
))
#base = base.add(Point(letter_spacing, 0, 0))
# go to the next line
# go to the next line
base
=
(
origin
[
0
],
base
[
1
]
-
line_height
*
line_factor
,
origin
[
2
])
base
=
(
origin
[
0
],
base
[
1
]
-
line_height
*
line_factor
,
origin
[
2
])
#base = Point(origin.x, base.y - line_height * line_factor, origin.z)
if
not
current_line
.
maxx
is
None
:
if
not
current_line
.
maxx
is
None
:
if
align
==
TEXT_ALIGN_CENTER
:
if
align
==
TEXT_ALIGN_CENTER
:
current_line
.
shift
(
-
current_line
.
maxx
/
2
,
0
,
0
)
current_line
.
shift
(
-
current_line
.
maxx
/
2
,
0
,
0
)
...
...
pycam/Geometry/Line.py
View file @
73cb1bb0
...
@@ -54,18 +54,15 @@ class Line(IDGenerator, TransformableContainer):
...
@@ -54,18 +54,15 @@ class Line(IDGenerator, TransformableContainer):
def
vector
(
self
):
def
vector
(
self
):
if
self
.
_vector
is
None
:
if
self
.
_vector
is
None
:
self
.
_vector
=
psub
(
self
.
p2
,
self
.
p1
)
self
.
_vector
=
psub
(
self
.
p2
,
self
.
p1
)
#self._vector = self.p2.sub(self.p1)
return
self
.
_vector
return
self
.
_vector
@
property
@
property
def
dir
(
self
):
def
dir
(
self
):
return
pnormalized
(
self
.
vector
)
return
pnormalized
(
self
.
vector
)
#return self.vector.normalized()
@
property
@
property
def
len
(
self
):
def
len
(
self
):
return
pnorm
(
self
.
vector
)
return
pnorm
(
self
.
vector
)
#return self.vector.norm
@
property
@
property
def
minx
(
self
):
def
minx
(
self
):
...
@@ -125,8 +122,6 @@ class Line(IDGenerator, TransformableContainer):
...
@@ -125,8 +122,6 @@ class Line(IDGenerator, TransformableContainer):
def
next
(
self
):
def
next
(
self
):
yield
"p1"
yield
"p1"
#yield self.p1
#yield lambda x: self.p2 = x
yield
"p2"
yield
"p2"
def
get_children_count
(
self
):
def
get_children_count
(
self
):
...
@@ -147,13 +142,11 @@ class Line(IDGenerator, TransformableContainer):
...
@@ -147,13 +142,11 @@ class Line(IDGenerator, TransformableContainer):
def
point_with_length_multiply
(
self
,
l
):
def
point_with_length_multiply
(
self
,
l
):
return
padd
(
self
.
p1
,
pmul
(
self
.
dir
,
l
*
self
.
len
))
return
padd
(
self
.
p1
,
pmul
(
self
.
dir
,
l
*
self
.
len
))
#return self.p1.add(self.dir.mul(l*self.len))
def
get_length_line
(
self
,
length
):
def
get_length_line
(
self
,
length
):
""" return a line with the same direction and the specified length
""" return a line with the same direction and the specified length
"""
"""
return
Line
(
self
.
p1
,
padd
(
self
.
p1
,
pmul
(
self
.
dir
,
length
)))
return
Line
(
self
.
p1
,
padd
(
self
.
p1
,
pmul
(
self
.
dir
,
length
)))
#return Line(self.p1, self.p1.add(self.dir.mul(length)))
def
closest_point
(
self
,
p
):
def
closest_point
(
self
,
p
):
v
=
self
.
dir
v
=
self
.
dir
...
@@ -161,13 +154,10 @@ class Line(IDGenerator, TransformableContainer):
...
@@ -161,13 +154,10 @@ class Line(IDGenerator, TransformableContainer):
# for zero-length lines
# for zero-length lines
return
self
.
p1
return
self
.
p1
l
=
pdot
(
self
.
p1
,
v
)
-
pdot
(
p
,
v
)
l
=
pdot
(
self
.
p1
,
v
)
-
pdot
(
p
,
v
)
#l = self.p1.dot(v) - p.dot(v)
return
psub
(
self
.
p1
,
pmul
(
v
,
l
))
return
psub
(
self
.
p1
,
pmul
(
v
,
l
))
#return self.p1.sub(v.mul(l))
def
dist_to_point_sq
(
self
,
p
):
def
dist_to_point_sq
(
self
,
p
):
return
pnormsq
(
psub
(
p
,
self
.
closes_point
(
p
)))
return
pnormsq
(
psub
(
p
,
self
.
closes_point
(
p
)))
#return p.sub(self.closest_point(p)).normsq
def
dist_to_point
(
self
,
p
):
def
dist_to_point
(
self
,
p
):
return
sqrt
(
self
.
dist_to_point_sq
(
p
))
return
sqrt
(
self
.
dist_to_point_sq
(
p
))
...
@@ -178,9 +168,7 @@ class Line(IDGenerator, TransformableContainer):
...
@@ -178,9 +168,7 @@ class Line(IDGenerator, TransformableContainer):
return
True
return
True
dir1
=
pnormalized
(
psub
(
p
,
self
.
p1
))
dir1
=
pnormalized
(
psub
(
p
,
self
.
p1
))
#dir1 = p.sub(self.p1).normalized()
dir2
=
pnormalized
(
psub
(
self
.
p2
,
p
))
dir2
=
pnormalized
(
psub
(
self
.
p2
,
p
))
#dir2 = self.p2.sub(p).normalized()
# True if the two parts of the line have the same direction or if the
# True if the two parts of the line have the same direction or if the
# point is self.p1 or self.p2.
# point is self.p1 or self.p2.
return
(
dir1
==
dir2
==
self
.
dir
)
or
(
dir1
is
None
)
or
(
dir2
is
None
)
return
(
dir1
==
dir2
==
self
.
dir
)
or
(
dir1
is
None
)
or
(
dir2
is
None
)
...
@@ -210,19 +198,14 @@ class Line(IDGenerator, TransformableContainer):
...
@@ -210,19 +198,14 @@ class Line(IDGenerator, TransformableContainer):
"""
"""
x1
,
x2
,
x3
,
x4
=
self
.
p1
,
self
.
p2
,
line
.
p1
,
line
.
p2
x1
,
x2
,
x3
,
x4
=
self
.
p1
,
self
.
p2
,
line
.
p1
,
line
.
p2
a
=
psub
(
x2
,
x1
)
a
=
psub
(
x2
,
x1
)
#a = x2.sub(x1)
b
=
psub
(
x4
,
x3
)
b
=
psub
(
x4
,
x3
)
#b = x4.sub(x3)
c
=
psub
(
x3
,
x1
)
c
=
psub
(
x3
,
x1
)
#c = x3.sub(x1)
# see http://mathworld.wolfram.com/Line-LineIntersection.html (24)
# see http://mathworld.wolfram.com/Line-LineIntersection.html (24)
try
:
try
:
factor
=
pdot
(
pcross
(
c
,
b
),
pcross
(
a
,
b
))
/
pnormsq
(
pcross
(
a
,
b
))
factor
=
pdot
(
pcross
(
c
,
b
),
pcross
(
a
,
b
))
/
pnormsq
(
pcross
(
a
,
b
))
#factor = c.cross(b).dot(a.cross(b)) / a.cross(b).normsq
except
ZeroDivisionError
:
except
ZeroDivisionError
:
# lines are parallel
# lines are parallel
# check if they are _one_ line
# check if they are _one_ line
#if a.cross(c).norm != 0:
if
pnorm
(
pcross
(
a
,
c
))
!=
0
:
if
pnorm
(
pcross
(
a
,
c
))
!=
0
:
# the lines are parallel with a distance
# the lines are parallel with a distance
return
None
,
None
return
None
,
None
...
@@ -232,7 +215,6 @@ class Line(IDGenerator, TransformableContainer):
...
@@ -232,7 +215,6 @@ class Line(IDGenerator, TransformableContainer):
candidates
.
append
((
x3
,
pnorm
(
c
)
/
pnorm
(
a
)))
candidates
.
append
((
x3
,
pnorm
(
c
)
/
pnorm
(
a
)))
elif
self
.
is_point_inside
(
x4
):
elif
self
.
is_point_inside
(
x4
):
candidates
.
append
((
x4
,
pnorm
(
psub
(
line
.
p2
,
self
.
p1
))
/
pnorm
(
a
)))
candidates
.
append
((
x4
,
pnorm
(
psub
(
line
.
p2
,
self
.
p1
))
/
pnorm
(
a
)))
#candidates.append((x4, line.p2.sub(self.p1).norm / a.norm))
elif
line
.
is_point_inside
(
x1
):
elif
line
.
is_point_inside
(
x1
):
candidates
.
append
((
x1
,
0
))
candidates
.
append
((
x1
,
0
))
elif
line
.
is_point_inside
(
x2
):
elif
line
.
is_point_inside
(
x2
):
...
@@ -244,7 +226,6 @@ class Line(IDGenerator, TransformableContainer):
...
@@ -244,7 +226,6 @@ class Line(IDGenerator, TransformableContainer):
return
candidates
[
0
]
return
candidates
[
0
]
if
infinite_lines
or
(
-
epsilon
<=
factor
<=
1
+
epsilon
):
if
infinite_lines
or
(
-
epsilon
<=
factor
<=
1
+
epsilon
):
intersection
=
padd
(
x1
,
pmul
(
a
,
factor
))
intersection
=
padd
(
x1
,
pmul
(
a
,
factor
))
#intersection = x1.add(a.mul(factor))
# check if the intersection is between x3 and x4
# check if the intersection is between x3 and x4
if
infinite_lines
:
if
infinite_lines
:
return
intersection
,
factor
return
intersection
,
factor
...
...
pycam/Geometry/Model.py
View file @
73cb1bb0
...
@@ -980,7 +980,6 @@ class PolygonGroup(object):
...
@@ -980,7 +980,6 @@ class PolygonGroup(object):
line_distances
=
[]
line_distances
=
[]
for
line
in
self
.
lines
:
for
line
in
self
.
lines
:
cross_product
=
pcross
(
line
.
dir
,
psub
(
point
,
line
.
p1
))
cross_product
=
pcross
(
line
.
dir
,
psub
(
point
,
line
.
p1
))
#cross_product = line.dir.cross(point.sub(line.p1))
if
cross_product
[
2
]
>
0
:
if
cross_product
[
2
]
>
0
:
close_points
=
[]
close_points
=
[]
close_point
=
line
.
closest_point
(
point
)
close_point
=
line
.
closest_point
(
point
)
...
@@ -991,9 +990,7 @@ class PolygonGroup(object):
...
@@ -991,9 +990,7 @@ class PolygonGroup(object):
close_points
.
append
(
close_point
)
close_points
.
append
(
close_point
)
for
p
in
close_points
:
for
p
in
close_points
:
direction
=
psub
(
point
,
p
)
direction
=
psub
(
point
,
p
)
#direction = point.sub(p)
dist
=
pnorm
(
direction
)
dist
=
pnorm
(
direction
)
#dist = direction.norm
line_distances
.
append
(
dist
)
line_distances
.
append
(
dist
)
elif
cross_product
.
z
==
0
:
elif
cross_product
.
z
==
0
:
# the point is on the line
# the point is on the line
...
@@ -1071,7 +1068,6 @@ class Rectangle(IDGenerator, TransformableContainer):
...
@@ -1071,7 +1068,6 @@ class Rectangle(IDGenerator, TransformableContainer):
orders
=
((
p1
,
p2
,
p3
,
p4
),
(
p1
,
p2
,
p4
,
p3
),
(
p1
,
p3
,
p2
,
p4
),
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
))
(
p1
,
p3
,
p4
,
p2
),
(
p1
,
p4
,
p2
,
p3
),
(
p1
,
p4
,
p3
,
p2
))
for
order
in
orders
:
for
order
in
orders
:
#if abs(order[0].sub(order[2]).norm - order[1].sub(order[3]).norm) < epsilon:
if
abs
(
pnorm
(
psub
(
order
[
0
],
order
[
2
]))
-
pnorm
(
psub
(
order
[
1
],
order
[
3
])))
<
epsilon
:
if
abs
(
pnorm
(
psub
(
order
[
0
],
order
[
2
]))
-
pnorm
(
psub
(
order
[
1
],
order
[
3
])))
<
epsilon
:
t1
=
Triangle
(
order
[
0
],
order
[
1
],
order
[
2
])
t1
=
Triangle
(
order
[
0
],
order
[
1
],
order
[
2
])
t2
=
Triangle
(
order
[
2
],
order
[
3
],
order
[
0
])
t2
=
Triangle
(
order
[
2
],
order
[
3
],
order
[
0
])
...
@@ -1101,10 +1097,6 @@ class Rectangle(IDGenerator, TransformableContainer):
...
@@ -1101,10 +1097,6 @@ class Rectangle(IDGenerator, TransformableContainer):
return
(
self
.
p1
,
self
.
p2
,
self
.
p3
,
self
.
p4
)
return
(
self
.
p1
,
self
.
p2
,
self
.
p3
,
self
.
p4
)
def
next
(
self
):
def
next
(
self
):
#yield self.p1
#yield self.p2
#yield self.p3
#yield self.p4
yield
"p1"
yield
"p1"
yield
"p2"
yield
"p2"
yield
"p3"
yield
"p3"
...
@@ -1141,7 +1133,6 @@ class Rectangle(IDGenerator, TransformableContainer):
...
@@ -1141,7 +1133,6 @@ class Rectangle(IDGenerator, TransformableContainer):
log
.
error
(
"Invalid number of vertices:
%
s"
%
unique_vertices
)
log
.
error
(
"Invalid number of vertices:
%
s"
%
unique_vertices
)
return
None
return
None
if
abs
(
pnorm
(
psub
(
unique_verticies
[
0
],
unique_verticies
[
1
]))
-
pnorm
(
psub
(
shared_vertices
[
0
],
shared_vertices
[
1
])))
<
epsilon
:
if
abs
(
pnorm
(
psub
(
unique_verticies
[
0
],
unique_verticies
[
1
]))
-
pnorm
(
psub
(
shared_vertices
[
0
],
shared_vertices
[
1
])))
<
epsilon
:
#if abs(unique_vertices[0].sub(unique_vertices[1]).norm - shared_vertices[0].sub(shared_vertices[1]).norm) < epsilon:
try
:
try
:
return
Rectangle
(
unique_vertices
[
0
],
unique_vertices
[
1
],
return
Rectangle
(
unique_vertices
[
0
],
unique_vertices
[
1
],
shared_vertices
[
0
],
shared_vertices
[
1
],
shared_vertices
[
0
],
shared_vertices
[
1
],
...
...
pycam/Geometry/Plane.py
View file @
73cb1bb0
...
@@ -77,13 +77,10 @@ class Plane(IDGenerator, TransformableContainer):
...
@@ -77,13 +77,10 @@ class Plane(IDGenerator, TransformableContainer):
if
direction
is
None
:
if
direction
is
None
:
return
(
None
,
INFINITE
)
return
(
None
,
INFINITE
)
denom
=
pdot
(
self
.
n
,
direction
)
denom
=
pdot
(
self
.
n
,
direction
)
#denom = self.n.dot(direction)
if
denom
==
0
:
if
denom
==
0
:
return
(
None
,
INFINITE
)
return
(
None
,
INFINITE
)
l
=
-
(
pdot
(
self
.
n
,
point
)
-
pdot
(
self
.
n
,
self
.
p
))
/
denom
l
=
-
(
pdot
(
self
.
n
,
point
)
-
pdot
(
self
.
n
,
self
.
p
))
/
denom
#l = -(self.n.dot(point) - self.n.dot(self.p)) / denom
cp
=
padd
(
point
,
pmul
(
direction
,
l
))
cp
=
padd
(
point
,
pmul
(
direction
,
l
))
#cp = point.add(direction.mul(l))
return
(
cp
,
l
)
return
(
cp
,
l
)
def
intersect_triangle
(
self
,
triangle
,
counter_clockwise
=
False
):
def
intersect_triangle
(
self
,
triangle
,
counter_clockwise
=
False
):
...
@@ -121,8 +118,6 @@ class Plane(IDGenerator, TransformableContainer):
...
@@ -121,8 +118,6 @@ class Plane(IDGenerator, TransformableContainer):
if
collision_line
.
len
==
0
:
if
collision_line
.
len
==
0
:
return
collision_line
return
collision_line
cross
=
pcross
(
self
.
n
,
collision_line
.
dir
)
cross
=
pcross
(
self
.
n
,
collision_line
.
dir
)
#cross = self.n.cross(collision_line.dir)
#if (cross.dot(triangle.normal) < 0) == bool(not counter_clockwise):
if
(
pdot
(
cross
,
triangle
.
normal
)
<
0
)
==
bool
(
not
counter_clockwise
):
if
(
pdot
(
cross
,
triangle
.
normal
)
<
0
)
==
bool
(
not
counter_clockwise
):
# anti-clockwise direction -> revert the direction of the line
# anti-clockwise direction -> revert the direction of the line
collision_line
=
Line
(
collision_line
.
p2
,
collision_line
.
p1
)
collision_line
=
Line
(
collision_line
.
p2
,
collision_line
.
p1
)
...
...
pycam/Geometry/PointKdtree.py
View file @
73cb1bb0
...
@@ -47,7 +47,6 @@ class PointKdtree(kdtree):
...
@@ -47,7 +47,6 @@ class PointKdtree(kdtree):
return
dx
*
dx
+
dy
*
dy
+
dz
*
dz
return
dx
*
dx
+
dy
*
dy
+
dz
*
dz
def
Point
(
self
,
x
,
y
,
z
):
def
Point
(
self
,
x
,
y
,
z
):
#return Point(x,y,z)
if
self
.
_n
:
if
self
.
_n
:
n
=
self
.
_n
n
=
self
.
_n
n
.
bound
=
(
x
,
y
,
z
)
n
.
bound
=
(
x
,
y
,
z
)
...
...
pycam/Geometry/Polygon.py
View file @
73cb1bb0
This diff is collapsed.
Click to expand it.
pycam/Geometry/PolygonExtractor.py
View file @
73cb1bb0
This diff is collapsed.
Click to expand it.
pycam/Geometry/Triangle.py
View file @
73cb1bb0
...
@@ -65,26 +65,18 @@ class Triangle(IDGenerator, TransformableContainer):
...
@@ -65,26 +65,18 @@ class Triangle(IDGenerator, TransformableContainer):
# calculate normal, if p1-p2-pe are in clockwise order
# calculate normal, if p1-p2-pe are in clockwise order
if
self
.
normal
is
None
:
if
self
.
normal
is
None
:
self
.
normal
=
pnormalized
(
pcross
(
psub
(
self
.
p3
,
self
.
p1
),
psub
(
self
.
p2
,
self
.
p1
)))
self
.
normal
=
pnormalized
(
pcross
(
psub
(
self
.
p3
,
self
.
p1
),
psub
(
self
.
p2
,
self
.
p1
)))
#self.normal = self.p3.sub(self.p1).cross(self.p2.sub( \
# self.p1)).normalized()
if
not
len
(
self
.
normal
)
>
3
:
if
not
len
(
self
.
normal
)
>
3
:
self
.
normal
=
(
self
.
normal
[
0
],
self
.
normal
[
1
],
self
.
normal
[
2
],
'v'
)
self
.
normal
=
(
self
.
normal
[
0
],
self
.
normal
[
1
],
self
.
normal
[
2
],
'v'
)
self
.
center
=
pdiv
(
padd
(
padd
(
self
.
p1
,
self
.
p2
),
self
.
p3
),
3
)
self
.
center
=
pdiv
(
padd
(
padd
(
self
.
p1
,
self
.
p2
),
self
.
p3
),
3
)
# self.center = self.p1.add(self.p2).add(self.p3).div(3)
self
.
plane
=
Plane
(
self
.
center
,
self
.
normal
)
self
.
plane
=
Plane
(
self
.
center
,
self
.
normal
)
# calculate circumcircle (resulting in radius and middle)
# calculate circumcircle (resulting in radius and middle)
denom
=
pnorm
(
pcross
(
psub
(
self
.
p2
,
self
.
p1
),
psub
(
self
.
p3
,
self
.
p2
)))
denom
=
pnorm
(
pcross
(
psub
(
self
.
p2
,
self
.
p1
),
psub
(
self
.
p3
,
self
.
p2
)))
#denom = self.p2.sub(self.p1).cross(self.p3.sub(self.p2)).norm
self
.
radius
=
(
pnorm
(
psub
(
self
.
p2
,
self
.
p1
))
*
pnorm
(
psub
(
self
.
p3
,
self
.
p2
))
*
pnorm
(
psub
(
self
.
p3
,
self
.
p1
)))
/
(
2
*
denom
)
self
.
radius
=
(
pnorm
(
psub
(
self
.
p2
,
self
.
p1
))
*
pnorm
(
psub
(
self
.
p3
,
self
.
p2
))
*
pnorm
(
psub
(
self
.
p3
,
self
.
p1
)))
/
(
2
*
denom
)
#self.radius = (self.p2.sub(self.p1).norm * self.p3.sub(self.p2).norm * self.p3.sub(self.p1).norm) / (2 * denom)
self
.
radiussq
=
self
.
radius
**
2
self
.
radiussq
=
self
.
radius
**
2
denom2
=
2
*
denom
*
denom
denom2
=
2
*
denom
*
denom
alpha
=
pnormsq
(
psub
(
self
.
p3
,
self
.
p2
))
*
pdot
(
psub
(
self
.
p1
,
self
.
p2
),
psub
(
self
.
p1
,
self
.
p3
))
/
denom2
alpha
=
pnormsq
(
psub
(
self
.
p3
,
self
.
p2
))
*
pdot
(
psub
(
self
.
p1
,
self
.
p2
),
psub
(
self
.
p1
,
self
.
p3
))
/
denom2
#alpha = self.p3.sub(self.p2).normsq * self.p1.sub(self.p2).dot(self.p1.sub(self.p3)) / denom2
beta
=
pnormsq
(
psub
(
self
.
p1
,
self
.
p3
))
*
pdot
(
psub
(
self
.
p2
,
self
.
p1
),
psub
(
self
.
p2
,
self
.
p3
))
/
denom2
beta
=
pnormsq
(
psub
(
self
.
p1
,
self
.
p3
))
*
pdot
(
psub
(
self
.
p2
,
self
.
p1
),
psub
(
self
.
p2
,
self
.
p3
))
/
denom2
#beta = self.p1.sub(self.p3).normsq * self.p2.sub(self.p1).dot(self.p2.sub(self.p3)) / denom2
gamma
=
pnormsq
(
psub
(
self
.
p1
,
self
.
p2
))
*
pdot
(
psub
(
self
.
p3
,
self
.
p1
),
psub
(
self
.
p3
,
self
.
p2
))
/
denom2
gamma
=
pnormsq
(
psub
(
self
.
p1
,
self
.
p2
))
*
pdot
(
psub
(
self
.
p3
,
self
.
p1
),
psub
(
self
.
p3
,
self
.
p2
))
/
denom2
#gamma = self.p1.sub(self.p2).normsq * self.p3.sub(self.p1).dot(self.p3.sub(self.p2)) / denom2
self
.
middle
=
(
self
.
p1
[
0
]
*
alpha
+
self
.
p2
[
0
]
*
beta
+
self
.
p3
[
0
]
*
gamma
,
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
[
1
]
*
alpha
+
self
.
p2
[
1
]
*
beta
+
self
.
p3
[
1
]
*
gamma
,
self
.
p1
[
2
]
*
alpha
+
self
.
p2
[
2
]
*
beta
+
self
.
p3
[
2
]
*
gamma
)
self
.
p1
[
2
]
*
alpha
+
self
.
p2
[
2
]
*
beta
+
self
.
p3
[
2
]
*
gamma
)
...
@@ -145,17 +137,12 @@ class Triangle(IDGenerator, TransformableContainer):
...
@@ -145,17 +137,12 @@ class Triangle(IDGenerator, TransformableContainer):
c
=
self
.
center
c
=
self
.
center
GL
.
glTranslate
(
c
[
0
],
c
[
1
],
c
[
2
])
GL
.
glTranslate
(
c
[
0
],
c
[
1
],
c
[
2
])
p12
=
pmul
(
padd
(
self
.
p1
,
self
.
p2
),
0.5
)
p12
=
pmul
(
padd
(
self
.
p1
,
self
.
p2
),
0.5
)
#p12 = self.p1.add(self.p2).mul(0.5)
p3_12
=
pnormalized
(
psub
(
self
.
p3
,
p12
))
p3_12
=
pnormalized
(
psub
(
self
.
p3
,
p12
))
#p3_12 = self.p3.sub(p12).normalized()
p2_1
=
pnormalized
(
psub
(
self
.
p1
,
self
.
p2
))
p2_1
=
pnormalized
(
psub
(
self
.
p1
,
self
.
p2
))
#p2_1 = self.p1.sub(self.p2).normalized()
pn
=
pcross
(
p2_1
,
p3_12
)
pn
=
pcross
(
p2_1
,
p3_12
)
#pn = p2_1.cross(p3_12)
GL
.
glMultMatrixf
((
p2_1
[
0
],
p2_1
[
1
],
p2_1
[
2
],
0
,
p3_12
[
0
],
p3_12
[
1
],
GL
.
glMultMatrixf
((
p2_1
[
0
],
p2_1
[
1
],
p2_1
[
2
],
0
,
p3_12
[
0
],
p3_12
[
1
],
p3_12
[
2
],
0
,
pn
[
0
],
pn
[
1
],
pn
[
2
],
0
,
0
,
0
,
0
,
1
))
p3_12
[
2
],
0
,
pn
[
0
],
pn
[
1
],
pn
[
2
],
0
,
0
,
0
,
0
,
1
))
n
=
pmul
(
self
.
normal
,
0.01
)
n
=
pmul
(
self
.
normal
,
0.01
)
#n = self.normal.mul(0.01)
GL
.
glTranslatef
(
n
[
0
],
n
[
1
],
n
[
2
])
GL
.
glTranslatef
(
n
[
0
],
n
[
1
],
n
[
2
])
maxdim
=
max
((
self
.
maxx
-
self
.
minx
),
(
self
.
maxy
-
self
.
miny
),
maxdim
=
max
((
self
.
maxx
-
self
.
minx
),
(
self
.
maxy
-
self
.
miny
),
(
self
.
maxz
-
self
.
minz
))
(
self
.
maxz
-
self
.
minz
))
...
@@ -172,19 +159,13 @@ class Triangle(IDGenerator, TransformableContainer):
...
@@ -172,19 +159,13 @@ class Triangle(IDGenerator, TransformableContainer):
if
False
:
# draw point id on triangle face
if
False
:
# draw point id on triangle face
c
=
self
.
center
c
=
self
.
center
p12
=
pmul
(
padd
(
self
.
p1
,
self
.
p2
),
0.5
)
p12
=
pmul
(
padd
(
self
.
p1
,
self
.
p2
),
0.5
)
#p12 = self.p1.add(self.p2).mul(0.5)
p3_12
=
pnormalized
(
psub
(
self
.
p3
,
p12
))
p3_12
=
pnormalized
(
psub
(
self
.
p3
,
p12
))
#p3_12 = self.p3.sub(p12).normalized()
p2_1
=
pnormalized
(
psub
(
self
.
p1
,
self
.
p2
))
p2_1
=
pnormalized
(
psub
(
self
.
p1
,
self
.
p2
))
#p2_1 = self.p1.sub(self.p2).normalized()
pn
=
pcross
(
p2_1
,
p3_12
)
pn
=
pcross
(
p2_1
,
p3_12
)
#pn = p2_1.cross(p3_12)
n
=
pmul
(
self
.
normal
,
0.01
)
n
=
pmul
(
self
.
normal
,
0.01
)
#n = self.normal.mul(0.01)
for
p
in
(
self
.
p1
,
self
.
p2
,
self
.
p3
):
for
p
in
(
self
.
p1
,
self
.
p2
,
self
.
p3
):
GL
.
glPushMatrix
()
GL
.
glPushMatrix
()
pp
=
psub
(
p
,
pmul
(
psub
(
p
,
c
),
0.3
))
pp
=
psub
(
p
,
pmul
(
psub
(
p
,
c
),
0.3
))
#pp = p.sub(p.sub(c).mul(0.3))
GL
.
glTranslate
(
pp
[
0
],
pp
[
1
],
pp
[
2
])
GL
.
glTranslate
(
pp
[
0
],
pp
[
1
],
pp
[
2
])
GL
.
glMultMatrixf
((
p2_1
[
0
],
p2_1
[
1
],
p2_1
[
2
],
0
,
p3_12
[
0
],
p3_12
[
1
],
GL
.
glMultMatrixf
((
p2_1
[
0
],
p2_1
[
1
],
p2_1
[
2
],
0
,
p3_12
[
0
],
p3_12
[
1
],
p3_12
[
2
],
0
,
pn
[
0
],
pn
[
1
],
pn
[
2
],
0
,
0
,
0
,
0
,
1
))
p3_12
[
2
],
0
,
pn
[
0
],
pn
[
1
],
pn
[
2
],
0
,
0
,
0
,
0
,
1
))
...
@@ -202,17 +183,14 @@ class Triangle(IDGenerator, TransformableContainer):
...
@@ -202,17 +183,14 @@ class Triangle(IDGenerator, TransformableContainer):
# http://www.blackpawn.com/texts/pointinpoly/default.html
# http://www.blackpawn.com/texts/pointinpoly/default.html
# Compute vectors
# Compute vectors
v0
=
psub
(
self
.
p3
,
self
.
p1
)
v0
=
psub
(
self
.
p3
,
self
.
p1
)
#v0 = self.p3.sub(self.p1)
v1
=
psub
(
self
.
p2
,
self
.
p1
)
v1
=
psub
(
self
.
p2
,
self
.
p1
)
#v1 = self.p2.sub(self.p1)
v2
=
psub
(
p
,
self
.
p1
)
v2
=
psub
(
p
,
self
.
p1
)
#v2 = p.sub(self.p1)
# Compute dot products
# Compute dot products
dot00
=
pdot
(
v0
,
v0
)
# dot00 = v0.dot(v0)
dot00
=
pdot
(
v0
,
v0
)
dot01
=
pdot
(
v0
,
v1
)
# dot01 = v0.dot(v1)
dot01
=
pdot
(
v0
,
v1
)
dot02
=
pdot
(
v0
,
v2
)
# dot02 = v0.dot(v2)
dot02
=
pdot
(
v0
,
v2
)
dot11
=
pdot
(
v1
,
v1
)
# dot11 = v1.dot(v1)
dot11
=
pdot
(
v1
,
v1
)
dot12
=
pdot
(
v1
,
v2
)
# dot12 = v1.dot(v2)
dot12
=
pdot
(
v1
,
v2
)
# Compute barycentric coordinates
# Compute barycentric coordinates
denom
=
dot00
*
dot11
-
dot01
*
dot01
denom
=
dot00
*
dot11
-
dot01
*
dot01
if
denom
==
0
:
if
denom
==
0
:
...
@@ -232,11 +210,8 @@ class Triangle(IDGenerator, TransformableContainer):
...
@@ -232,11 +210,8 @@ class Triangle(IDGenerator, TransformableContainer):
sub
.
append
(
self
)
sub
.
append
(
self
)
else
:
else
:
p4
=
pdiv
(
padd
(
self
.
p1
,
self
.
p2
),
2
)
p4
=
pdiv
(
padd
(
self
.
p1
,
self
.
p2
),
2
)
#p4 = self.p1.add(self.p2).div(2)
p5
=
pdiv
(
padd
(
self
.
p2
,
self
.
p3
),
2
)
p5
=
pdiv
(
padd
(
self
.
p2
,
self
.
p3
),
2
)
#p5 = self.p2.add(self.p3).div(2)
p6
=
pdiv
(
padd
(
self
.
p3
,
self
.
p1
),
2
)
p6
=
pdiv
(
padd
(
self
.
p3
,
self
.
p1
),
2
)
#p6 = self.p3.add(self.p1).div(2)
sub
+=
Triangle
(
self
.
p1
,
p4
,
p6
)
.
subdivide
(
depth
-
1
)
sub
+=
Triangle
(
self
.
p1
,
p4
,
p6
)
.
subdivide
(
depth
-
1
)
sub
+=
Triangle
(
p6
,
p5
,
self
.
p3
)
.
subdivide
(
depth
-
1
)
sub
+=
Triangle
(
p6
,
p5
,
self
.
p3
)
.
subdivide
(
depth
-
1
)
sub
+=
Triangle
(
p6
,
p4
,
p5
)
.
subdivide
(
depth
-
1
)
sub
+=
Triangle
(
p6
,
p4
,
p5
)
.
subdivide
(
depth
-
1
)
...
@@ -245,6 +220,5 @@ class Triangle(IDGenerator, TransformableContainer):
...
@@ -245,6 +220,5 @@ class Triangle(IDGenerator, TransformableContainer):
def
get_area
(
self
):
def
get_area
(
self
):
cross
=
pcross
(
psub
(
self
.
p2
,
self
.
p1
),
psub
(
self
.
p3
,
self
.
p1
))
cross
=
pcross
(
psub
(
self
.
p2
,
self
.
p1
),
psub
(
self
.
p3
,
self
.
p1
))
#cross = self.p2.sub(self.p1).cross(self.p3.sub(self.p1))
return
pnorm
(
cross
)
/
2
return
pnorm
(
cross
)
/
2
pycam/Geometry/__init__.py
View file @
73cb1bb0
...
@@ -38,23 +38,16 @@ def get_bisector(p1, p2, p3, up_vector):
...
@@ -38,23 +38,16 @@ def get_bisector(p1, p2, p3, up_vector):
of the angle.
of the angle.
"""
"""
d1
=
pnormalized
(
psub
(
p2
,
p1
))
d1
=
pnormalized
(
psub
(
p2
,
p1
))
#d1 = p2.sub(p1).normalized()
d2
=
pnormalized
(
psub
(
p2
,
p3
))
d2
=
pnormalized
(
psub
(
p2
,
p3
))
#d2 = p2.sub(p3).normalized()
bisector_dir
=
pnormalized
(
padd
(
d1
,
d2
))
bisector_dir
=
pnormalized
(
padd
(
d1
,
d2
))
#bisector_dir = d1.add(d2).normalized()
if
bisector_dir
is
None
:
if
bisector_dir
is
None
:
# the two vectors pointed to opposite directions
# the two vectors pointed to opposite directions
bisector_dir
=
pnormalized
(
pcross
(
d1
,
up_vector
))
bisector_dir
=
pnormalized
(
pcross
(
d1
,
up_vector
))
#bisector_dir = d1.cross(up_vector).normalized()
else
:
else
:
skel_up_vector
=
pcross
(
bisector_dir
,
psub
(
p2
,
p1
))
skel_up_vector
=
pcross
(
bisector_dir
,
psub
(
p2
,
p1
))
#skel_up_vector = bisector_dir.cross(p2.sub(p1))
#if up_vector.dot(skel_up_vector) < 0:
if
pdot
(
up_vector
,
skel_up_vector
)
<
0
:
if
pdot
(
up_vector
,
skel_up_vector
)
<
0
:
# reverse the skeleton vector to point outwards
# reverse the skeleton vector to point outwards
bisector_dir
=
pmul
(
bisector_dir
,
-
1
)
bisector_dir
=
pmul
(
bisector_dir
,
-
1
)
#bisector_dir = bisector_dir.mul(-1)
return
bisector_dir
return
bisector_dir
def
get_angle_pi
(
p1
,
p2
,
p3
,
up_vector
,
pi_factor
=
False
):
def
get_angle_pi
(
p1
,
p2
,
p3
,
up_vector
,
pi_factor
=
False
):
...
@@ -69,13 +62,10 @@ def get_angle_pi(p1, p2, p3, up_vector, pi_factor=False):
...
@@ -69,13 +62,10 @@ def get_angle_pi(p1, p2, p3, up_vector, pi_factor=False):
The result is in a range between 0 and 2*PI.
The result is in a range between 0 and 2*PI.
"""
"""
d1
=
pnormalized
(
psub
(
p2
,
p1
))
d1
=
pnormalized
(
psub
(
p2
,
p1
))
#d1 = p2.sub(p1).normalized()
d2
=
pnormalized
(
psub
(
p2
,
p3
))
d2
=
pnormalized
(
psub
(
p2
,
p3
))
#d2 = p2.sub(p3).normalized()
if
(
d1
is
None
)
or
(
d2
is
None
):
if
(
d1
is
None
)
or
(
d2
is
None
):
return
2
*
math
.
pi
return
2
*
math
.
pi
angle
=
math
.
acos
(
pdot
(
d1
,
d2
))
angle
=
math
.
acos
(
pdot
(
d1
,
d2
))
#angle = math.acos(d1.dot(d2))
# check the direction of the points (clockwise/anti)
# check the direction of the points (clockwise/anti)
# The code is taken from Polygon.get_area
# The code is taken from Polygon.get_area
value
=
[
0
,
0
,
0
]
value
=
[
0
,
0
,
0
]
...
@@ -145,7 +135,6 @@ def get_bezier_lines(points_with_bulge, segments=32):
...
@@ -145,7 +135,6 @@ def get_bezier_lines(points_with_bulge, segments=32):
# straight line
# straight line
return
[
Line
.
Line
(
p1
,
p2
)]
return
[
Line
.
Line
(
p1
,
p2
)]
straight_dir
=
pnormalized
(
psub
(
p2
,
p1
))
straight_dir
=
pnormalized
(
psub
(
p2
,
p1
))
#straight_dir = p2.sub(p1).normalized()
#bulge1 = max(-1.0, min(1.0, bulge1))
#bulge1 = max(-1.0, min(1.0, bulge1))
bulge1
=
math
.
atan
(
bulge1
)
bulge1
=
math
.
atan
(
bulge1
)
rot_matrix
=
Matrix
.
get_rotation_matrix_axis_angle
((
0
,
0
,
1
),
rot_matrix
=
Matrix
.
get_rotation_matrix_axis_angle
((
0
,
0
,
1
),
...
@@ -170,7 +159,6 @@ def get_bezier_lines(points_with_bulge, segments=32):
...
@@ -170,7 +159,6 @@ def get_bezier_lines(points_with_bulge, segments=32):
# and a bulge of 1 is a semicircle.
# and a bulge of 1 is a semicircle.
alpha
=
2
*
(
abs
(
bulge1
)
+
abs
(
bulge2
))
alpha
=
2
*
(
abs
(
bulge1
)
+
abs
(
bulge2
))
dist
=
pnorm
(
psub
(
p2
,
p1
))
dist
=
pnorm
(
psub
(
p2
,
p1
))
#dist = p2.sub(p1).norm
# calculate the radius of the circumcircle - avoiding divide-by-zero
# calculate the radius of the circumcircle - avoiding divide-by-zero
if
(
abs
(
alpha
)
<
epsilon
)
or
(
abs
(
math
.
pi
-
alpha
)
<
epsilon
):
if
(
abs
(
alpha
)
<
epsilon
)
or
(
abs
(
math
.
pi
-
alpha
)
<
epsilon
):
radius
=
dist
/
2.0
radius
=
dist
/
2.0
...
@@ -181,20 +169,11 @@ def get_bezier_lines(points_with_bulge, segments=32):
...
@@ -181,20 +169,11 @@ def get_bezier_lines(points_with_bulge, segments=32):
# seems to work well.
# seems to work well.
factor
=
4
*
radius
*
math
.
tan
(
alpha
/
4.0
)
factor
=
4
*
radius
*
math
.
tan
(
alpha
/
4.0
)
dir1
=
pmul
(
dir1
,
factor
)
dir1
=
pmul
(
dir1
,
factor
)
#dir1 = dir1.mul(factor)
dir2
=
pmul
(
dir2
,
factor
)
dir2
=
pmul
(
dir2
,
factor
)
#dir2 = dir2.mul(factor)
for
index
in
range
(
segments
+
1
):
for
index
in
range
(
segments
+
1
):
# t: 0..1
# t: 0..1
t
=
float
(
index
)
/
segments
t
=
float
(
index
)
/
segments
# see: http://en.wikipedia.org/wiki/Cubic_Hermite_spline
# see: http://en.wikipedia.org/wiki/Cubic_Hermite_spline
#p = p1.mul(2 * t ** 3 - 3 * t ** 2 + 1).add(
# dir1.mul(t ** 3 - 2 * t ** 2 + t).add(
# p2.mul(-2 * t ** 3 + 3 * t ** 2).add(
# dir2.mul(t ** 3 - t ** 2)
# )
# )
#)
p
=
padd
(
pmul
(
p1
,
2
*
t
**
3
-
3
*
t
**
2
+
1
)
,
padd
(
pmul
(
dir1
,
t
**
3
-
2
*
t
**
2
+
t
),
padd
(
pmul
(
p2
,
-
2
*
t
**
3
+
3
*
t
**
2
)
,
pmul
(
dir2
,
t
**
3
-
t
**
2
))))
p
=
padd
(
pmul
(
p1
,
2
*
t
**
3
-
3
*
t
**
2
+
1
)
,
padd
(
pmul
(
dir1
,
t
**
3
-
2
*
t
**
2
+
t
),
padd
(
pmul
(
p2
,
-
2
*
t
**
3
+
3
*
t
**
2
)
,
pmul
(
dir2
,
t
**
3
-
t
**
2
))))
result_points
.
append
(
p
)
result_points
.
append
(
p
)
# create lines
# create lines
...
...
pycam/Geometry/intersection.py
View file @
73cb1bb0
This diff is collapsed.
Click to expand it.
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