Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
asantosnet
Poisson_Solver
Commits
9a687f26
Commit
9a687f26
authored
Sep 28, 2018
by
pacome
Browse files
Add box function to create the corners of 2d and3d box
parent
dd25dc23
Changes
1
Hide whitespace changes
Inline
Side-by-side
poisson/continuous/shapes.py
View file @
9a687f26
...
...
@@ -820,6 +820,62 @@ class InHull(Shape):
#####################
def
box
(
length
,
corner
=
None
,
center
=
None
):
'''
Returns points of a 2d of 3d box
Parameters:
-----------
length = (Lx, Ly, Lz): numbers
the lengths of the sides
if Ly (Lz) is None, Ly (Lz) will be equal to Lx
(usefull to quickly draw cubes)
corner = (x0, y0, z0) : numbers
the lower left corner of the (if z0 si None will be 2d)
center = (x0, y0, z0) : numbers
overwrites the corner argument
if center=None the corner will be used
the lower left corner of the (if z0 si None will be 2d)
Returns:
--------
points: np.ndarray
the points defining the box
'''
if
isinstance
(
length
,
(
int
,
float
)):
length
=
(
length
,
length
)
length
=
np
.
asarray
(
length
)
ndim
=
len
(
length
)
if
corner
is
None
:
corner
=
np
.
zeros
(
ndim
)
elif
isinstance
(
corner
,
int
):
corner
=
corner
*
np
.
ones
(
ndim
)
corner
=
np
.
asarray
(
corner
)
if
center
is
not
None
:
center
=
np
.
asarray
(
center
)
assert
len
(
length
)
==
len
(
corner
),
(
'The corner does not have the same'
+
' size as length / or a corner has'
+
' been given and length is an int'
)
points
=
np
.
array
([[
0
,
0
],
[
0
,
length
[
1
]],
length
[:
2
],
[
length
[
0
],
0
]])
if
ndim
==
3
:
points
=
np
.
vstack
((
np
.
c_
[
points
,
np
.
zeros
(
4
)],
np
.
c_
[
points
,
np
.
ones
(
4
)
*
length
[
2
]]))
if
center
is
None
:
points
=
points
+
corner
else
:
points
=
points
-
length
/
2
+
center
return
points
def
translate
(
x
,
vect
):
'''
Translate a point or a list of points by a vector vect
...
...
Write
Preview
Supports
Markdown
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