Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
N
NTRfC
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
TFD - Institut für Turbomaschinen und Fluid-Dynamik
tools
NTRfC
Commits
fc4d096f
Commit
fc4d096f
authored
3 years ago
by
Malte Nyhuis
Browse files
Options
Downloads
Patches
Plain Diff
more tests
more tests
parent
9912a340
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
ntrfc/utils/math/vectorcalc.py
+11
-11
11 additions, 11 deletions
ntrfc/utils/math/vectorcalc.py
tests/test_ntrfc_math.py
+50
-0
50 additions, 0 deletions
tests/test_ntrfc_math.py
with
61 additions
and
11 deletions
ntrfc/utils/math/vectorcalc.py
+
11
−
11
View file @
fc4d096f
...
...
@@ -32,6 +32,11 @@ def calc_largedistant_idx(x_koords, y_koords):
return
index_1
,
index_2
def
symToMatrix
(
symTensor
):
"""
tested translates symmetric tensor notation to complete matrix
:param symTensor:
:return:
"""
# xx,xy,xz,yy,yz,zz
Matrix
=
np
.
array
([[
symTensor
[
0
],
symTensor
[
1
],
symTensor
[
2
]],
[
symTensor
[
1
],
symTensor
[
3
],
symTensor
[
4
]],
...
...
@@ -39,15 +44,12 @@ def symToMatrix(symTensor):
return
Matrix
def
symToMatrixPVPoly
(
symTensor
):
# xx,xy,xz,yy,yz,zz
Matrix
=
np
.
array
([[
symTensor
[
0
],
symTensor
[
3
],
symTensor
[
4
]],
[
symTensor
[
3
],
symTensor
[
1
],
symTensor
[
5
]],
[
symTensor
[
4
],
symTensor
[
5
],
symTensor
[
2
]]])
return
Matrix
def
gradToRad
(
angle
):
"""
tested method to translate from grad to rad
:param angle:
:return:
"""
return
(
angle
/
180
)
*
np
.
pi
...
...
@@ -62,6 +64,7 @@ def Rx(xAngle):
[
0
,
-
np
.
sin
(
xAngle
),
np
.
cos
(
xAngle
)]])
def
Ry
(
yAngle
):
"""
using radiant
...
...
@@ -220,8 +223,6 @@ def minDists(vecs):
return
mDist
def
vecProjection
(
direction
,
vector
):
unitDir
=
unitVec
(
direction
)
return
np
.
dot
(
vector
,
unitDir
)
*
unitDir
...
...
@@ -255,4 +256,3 @@ def lineseg_dist(p, a, b):
return
np
.
hypot
(
h
,
np
.
linalg
.
norm
(
c
))
This diff is collapsed.
Click to expand it.
tests/test_ntrfc_math.py
+
50
−
0
View file @
fc4d096f
import
numpy
as
np
import
pyvista
as
pv
from
ntrfc.utils.math.vectorcalc
import
lineseg_dist
def
test_absVec
():
from
ntrfc.utils.math.vectorcalc
import
vecAbs
...
...
@@ -28,3 +30,51 @@ def test_randomUnitVec():
from
ntrfc.utils.math.vectorcalc
import
randomUnitVec
,
vecAbs
rvec
=
randomUnitVec
()
assert
vecAbs
(
rvec
)
==
1
def
test_gradToRad
():
from
ntrfc.utils.math.vectorcalc
import
gradToRad
angle_grad
=
180
angle_rad
=
gradToRad
(
angle_grad
)
assert
np
.
pi
==
angle_rad
def
test_symToMatrix
():
from
ntrfc.utils.math.vectorcalc
import
symToMatrix
A
=
np
.
array
([
1
,
1
,
1
,
1
,
1
,
1
])
R
=
symToMatrix
(
A
)
assert
all
(
np
.
equal
(
np
.
ones
((
3
,
3
)),
R
).
flatten
())
def
test_Rx
():
from
ntrfc.utils.math.vectorcalc
import
gradToRad
,
Rx
angle
=
90
R
=
Rx
(
gradToRad
(
angle
))
test_vec
=
np
.
array
([
0
,
0
,
1
])
new_vec
=
np
.
dot
(
R
,
test_vec
)
assert
all
(
np
.
isclose
(
new_vec
,
np
.
array
([
0
,
1
,
0
])))
def
test_Ry
():
from
ntrfc.utils.math.vectorcalc
import
gradToRad
,
Ry
angle
=
90
R
=
Ry
(
gradToRad
(
angle
))
test_vec
=
np
.
array
([
1
,
0
,
0
])
new_vec
=
np
.
dot
(
R
,
test_vec
)
assert
all
(
np
.
isclose
(
new_vec
,
np
.
array
([
0
,
0
,
1
])))
def
test_Rz
():
from
ntrfc.utils.math.vectorcalc
import
gradToRad
,
Rz
angle
=
90
R
=
Rz
(
gradToRad
(
angle
))
test_vec
=
np
.
array
([
0
,
1
,
0
])
new_vec
=
np
.
dot
(
R
,
test_vec
)
assert
all
(
np
.
isclose
(
new_vec
,
np
.
array
([
1
,
0
,
0
])))
def
test_lineseg
():
import
pyvista
as
pv
line
=
pv
.
Line
()
testpt
=
np
.
array
([
0
,
1
,
0
])
pt_a
,
pt_b
=
line
.
points
[
0
],
line
.
points
[
-
1
]
assert
line
.
length
==
lineseg_dist
(
testpt
,
pt_a
,
pt_b
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment