move geometry to geometry2d and add new geometry module (3d)
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
"""Test of geometry module.
|
||||
|
||||
:Date: 2019-08-20
|
||||
:Date: 2019-12-21
|
||||
|
||||
.. module:: test_geometry
|
||||
:platform: *nix, Windows
|
||||
@@ -13,247 +13,95 @@ import unittest
|
||||
import os
|
||||
import sys
|
||||
import math
|
||||
from numpy import allclose
|
||||
sys.path.insert(0, os.path.abspath('../pylib'))
|
||||
from data import fold_list
|
||||
from geometry import translate_xy, rotate_xy, interpolate_hermite, lines, cubics
|
||||
from geometry_plot import plot_lines, plot_cubic_lines
|
||||
|
||||
from mathematics import vector
|
||||
from geometry import Direction, Point, CS, Wireframe, Polygon
|
||||
|
||||
class TestGeometry(unittest.TestCase):
|
||||
global_points = [(0, 0),
|
||||
(0, 3),
|
||||
(3, 3),
|
||||
(3, 0),
|
||||
(3, 6),
|
||||
(5, 6),
|
||||
(5, 3),
|
||||
(5, 0),
|
||||
(7, 0)]
|
||||
inc = [[1, 2],
|
||||
[2, 3],
|
||||
[4, 3],
|
||||
[3, 5],
|
||||
[5, 6],
|
||||
[6, 7],
|
||||
[7, 8],
|
||||
[9, 7]]
|
||||
|
||||
# global deformation, horizontal right, vertical down, rotation
|
||||
U = [
|
||||
0.00000, 0.00000, -5.02012,
|
||||
12.77012, 0.06333, -2.72988,
|
||||
12.69350, 0.08599, 3.14685,
|
||||
0.00000, 0.00000, -7.92017,
|
||||
-12.39817, 0.17450, 4.14446,
|
||||
-12.43490, 0.32001, -3.10697,
|
||||
-26.77684, 0.16528, 2.98214,
|
||||
0.00000, 0.00000, 0.00000,
|
||||
-26.50991, 0.00000, -1.36053,
|
||||
]
|
||||
U = [Ui/1000 for Ui in U]
|
||||
def test_Direction(self):
|
||||
p = Direction()
|
||||
self.assertIsInstance(
|
||||
p, list)
|
||||
self.assertEqual(
|
||||
p, [1, 0, 0, 0])
|
||||
self.assertEqual(
|
||||
Direction(2, 3, 4), [2, 3, 4, 0])
|
||||
|
||||
# global deformation, only horizontal right and vertical down
|
||||
U2 = [ui for i, ui in enumerate(U) if i%3 != 2]
|
||||
self.assertIsInstance(
|
||||
p, vector)
|
||||
self.assertEqual(
|
||||
p, vector([1, 0, 0, 0]))
|
||||
self.assertEqual(
|
||||
Direction(2, 3, 4), vector([2, 3, 4, 0]))
|
||||
|
||||
# global deformation, horizontal right, vertical up, rotation
|
||||
UN = [Ui if i%3 != 1 else -Ui for i, Ui in enumerate(U)]
|
||||
def test_Direction_xyz(self):
|
||||
self.assertEqual(
|
||||
Direction().xyz(), [1, 0, 0])
|
||||
self.assertEqual(
|
||||
Direction(1, -1, 1).xyz(), [1, -1, 1])
|
||||
|
||||
# local deformation, horizontal right, vertical down, rotation
|
||||
u = [
|
||||
[ 0.000000, 0.000000, -0.005020, -0.000063, 0.012770, -0.002730],
|
||||
[ 0.012770, 0.000063, -0.002730, 0.012693, 0.000086, 0.003147],
|
||||
[ 0.000000, 0.000000, -0.007920, -0.000086, 0.012693, 0.003147],
|
||||
[-0.000086, 0.012693, 0.003147, -0.000175, -0.012398, 0.004144],
|
||||
[-0.012398, 0.000175, 0.004144, -0.012435, 0.000320, -0.003107],
|
||||
[ 0.000320, 0.012435, -0.003107, 0.000165, 0.026777, 0.002982],
|
||||
[ 0.000165, 0.026777, 0.002982, 0.000000, 0.000000, 0.000000],
|
||||
[ 0.014705, -0.022058, -0.001361, 0.014716, -0.022371, 0.002982],
|
||||
]
|
||||
def test_Point(self):
|
||||
p = Point()
|
||||
self.assertIsInstance(
|
||||
p, list)
|
||||
self.assertEqual(
|
||||
p, [0, 0, 0, 1])
|
||||
self.assertEqual(
|
||||
Point(2, 3, 4), [2, 3, 4, 1])
|
||||
|
||||
# local deformation, horizontal right, vertical up, rotation
|
||||
uN = [[uii if i%3 != 1 else -uii for i, uii in enumerate(ui)] for ui in u]
|
||||
self.assertIsInstance(
|
||||
p, vector)
|
||||
self.assertEqual(
|
||||
p, vector([0, 0, 0, 1]))
|
||||
self.assertEqual(
|
||||
Point(2, 3, 4), vector([2, 3, 4, 1]))
|
||||
|
||||
# exaggeration factor for the deformation
|
||||
factor = 20
|
||||
def test_Point_xyz(self):
|
||||
self.assertEqual(
|
||||
Point().xyz(), [0, 0, 0])
|
||||
self.assertEqual(
|
||||
Point(1, -1, 1).xyz(), [1, -1, 1])
|
||||
|
||||
# test of cubic lines
|
||||
test_lns_l = [((0, 0), (0, 3), [0.0, -0.0, -0.1004, -0.00126, -0.2554, -0.0546]),
|
||||
((0, 3), (3, 3), [0.2554, -0.00126, -0.0546, 0.25386, -0.00172, 0.06294]),
|
||||
((3, 0), (3, 3), [0.0, -0.0, -0.1584, -0.00172, -0.25386, 0.06294]),
|
||||
((3, 3), (3, 6), [-0.00172, -0.25386, 0.06294, -0.0035, 0.24796, 0.08288]),
|
||||
((3, 6), (5, 6), [-0.24796, -0.0035, 0.08288, -0.2487, -0.0064, -0.06214]),
|
||||
((5, 6), (5, 3), [0.0064, -0.2487, -0.06214, 0.0033, -0.53554, 0.05964]),
|
||||
((5, 3), (5, 0), [0.0033, -0.53554, 0.05964, 0.0, -0.0, 0.0]),
|
||||
((7, 0), (5, 3), [0.2941, 0.44116, -0.02722, 0.29432, 0.44742, 0.05964])]
|
||||
test_lns_g = [((0, 0), (0, 3), [0.0, -0.0, -0.1004024, -0.0012666, -0.2554024, -0.0545976]),
|
||||
((0, 3), (3, 3), [0.2554024, -0.0012666, -0.0545976, 0.25387, -0.0017198, 0.062937]),
|
||||
((3, 0), (3, 3), [0.0, -0.0, -0.1584034, -0.0017198, -0.25387, 0.062937]),
|
||||
((3, 3), (3, 6), [-0.0017198, -0.25387, 0.062937, -0.00349, 0.2479634, 0.0828892]),
|
||||
((3, 6), (5, 6), [-0.2479634, -0.00349, 0.0828892, -0.248698, -0.0064002, -0.0621394]),
|
||||
((5, 6), (5, 3), [0.0064002, -0.248698, -0.0621394, 0.0033056, -0.5355368, 0.0596428]),
|
||||
((5, 3), (5, 0), [0.0033056, -0.5355368, 0.0596428, 0.0, 0.0, 0.0]),
|
||||
((7, 0), (5, 3), [0.2941010455782632, 0.441151568367395, -0.0272106, 0.29431194259286797, 0.4474271690373891, 0.0596428])]
|
||||
def test_Wireframe(self):
|
||||
self.assertEqual(
|
||||
Wireframe().points(), [])
|
||||
|
||||
def test_lines(self):
|
||||
"""test lines function (undeformed structure)"""
|
||||
lns = lines(self.global_points, inc=self.inc, index_offset=1)
|
||||
test = [((0, 0), (0, 3)), ((0, 3), (3, 3)), ((3, 0), (3, 3)),
|
||||
((3, 3), (3, 6)), ((3, 6), (5, 6)), ((5, 6), (5, 3)),
|
||||
((5, 3), (5, 0)), ((7, 0), (5, 3))]
|
||||
# it is possible to assign other objects then Points but/and the
|
||||
# class will not test if Points are used, this is just assumed
|
||||
self.assertEqual(
|
||||
Wireframe([]).points(), [[]])
|
||||
|
||||
self.assertEqual(lns, test)
|
||||
plot_lines(lns, linestyle=':')
|
||||
self.assertEqual(
|
||||
Wireframe(Point()).points(), [[0, 0, 0, 1]])
|
||||
self.assertEqual(
|
||||
Wireframe(Point()).points(), [vector([0, 0, 0, 1])])
|
||||
|
||||
def test_lines_deformation(self):
|
||||
"""test lines function with deformation (deformed structure)"""
|
||||
lns = lines(self.global_points, deformation=fold_list(self.U2, 2), factor=self.factor, inc=self.inc, index_offset=1)
|
||||
test = [((0.0, 0.0), (0.25540240000000003, 3.0012666)), ((0.25540240000000003, 3.0012666), (3.25387, 3.0017198)), ((3.0, 0.0), (3.25387, 3.0017198)), ((3.25387, 3.0017198), (2.7520366, 6.00349)), ((2.7520366, 6.00349), (4.751302, 6.0064002)), ((4.751302, 6.0064002), (4.4644632, 3.0033056)), ((4.4644632, 3.0033056), (5.0, 0.0)), ((6.4698018, 0.0), (4.4644632, 3.0033056))]
|
||||
self.assertEqual(lns, test)
|
||||
plot_lines(lns, color='C2')
|
||||
def test_Polygon(self):
|
||||
p0 = Point()
|
||||
p1 = Point(1, 0, 0)
|
||||
p2 = Point(1, 1, 1)
|
||||
p3 = Point(0, 1, 1)
|
||||
pg = Polygon(p0, p1, p2, p3)
|
||||
self.assertEqual(
|
||||
pg.points(),
|
||||
[[0, 0, 0, 1], [1, 0 , 0, 1], [1, 1, 1, 1], [0, 1, 1, 1], [0, 0, 0, 1]])
|
||||
|
||||
def test_translate_xy(self):
|
||||
"""test translate_xy function with single values"""
|
||||
x = 2
|
||||
y = 4
|
||||
xp, yp = translate_xy((0.5, 1), x, y)
|
||||
xt = 2.5
|
||||
yt = 5
|
||||
self.assertEqual(xp, xt)
|
||||
self.assertEqual(yp, yt)
|
||||
|
||||
def test_translate_xy_list(self):
|
||||
"""test translate_xy function"""
|
||||
x = [ 0. , 0.33333333, 0.66666667, 1. , 1.33333333,
|
||||
1.66666667, 2. , 2.33333333, 2.66666667, 3. ]
|
||||
y = [ 6.30000000e-05, -7.58828532e-04, -1.39770233e-03,
|
||||
-1.84370370e-03, -2.08691495e-03, -2.11741838e-03,
|
||||
-1.92529630e-03, -1.50063100e-03, -8.33504801e-04,
|
||||
8.60000000e-05]
|
||||
xp, yp = translate_xy((1, 0.001), x, y)
|
||||
xt = [1.0,
|
||||
1.3333333333333333,
|
||||
1.6666666666666665,
|
||||
2.0,
|
||||
2.333333333333333,
|
||||
2.666666666666667,
|
||||
3.0,
|
||||
3.333333333333333,
|
||||
3.6666666666666665,
|
||||
4.0]
|
||||
yt = [0.0010629999999999999,
|
||||
0.00024117146776406044,
|
||||
-0.00039770233196159102,
|
||||
-0.0008437037037037035,
|
||||
-0.0010869149519890263,
|
||||
-0.0011174183813443071,
|
||||
-0.00092529629629629624,
|
||||
-0.00050063100137174286,
|
||||
0.0001664951989026062,
|
||||
0.0010859999999999999]
|
||||
self.assertTrue(allclose(xp, xt))
|
||||
self.assertTrue(allclose(yp, yt))
|
||||
|
||||
def test_rotate_xy(self):
|
||||
"""test translate_xy function with single values"""
|
||||
x = 2
|
||||
y = 4
|
||||
xp, yp = rotate_xy((0.5, 1), math.pi/2, x, y)
|
||||
xt = -2.5
|
||||
yt = 2.5
|
||||
self.assertEqual(xp, xt)
|
||||
self.assertEqual(yp, yt)
|
||||
|
||||
def test_rotate_xy_list(self):
|
||||
"""test translate_xy function"""
|
||||
x = [ 0. , 0.33333333, 0.66666667, 1. , 1.33333333,
|
||||
1.66666667, 2. , 2.33333333, 2.66666667, 3. ]
|
||||
y = [ 6.30000000e-05, -7.58828532e-04, -1.39770233e-03,
|
||||
-1.84370370e-03, -2.08691495e-03, -2.11741838e-03,
|
||||
-1.92529630e-03, -1.50063100e-03, -8.33504801e-04,
|
||||
8.60000000e-05]
|
||||
xp, yp = rotate_xy((0, 0), math.pi/2, x, y)
|
||||
xt = [-6.3e-05,
|
||||
0.00075882853223595997,
|
||||
0.0013977023319616318,
|
||||
0.0018437037037037647,
|
||||
0.0020869149519891078,
|
||||
0.002117418381344409,
|
||||
0.0019252962962964188,
|
||||
0.0015006310013718858,
|
||||
0.0008335048010975571,
|
||||
-8.5999999999816312e-05]
|
||||
yt = [3.8576374173141622e-21,
|
||||
0.33333333333333331,
|
||||
0.66666666666666663,
|
||||
1.0,
|
||||
1.3333333333333333,
|
||||
1.6666666666666667,
|
||||
2.0,
|
||||
2.333333333333333,
|
||||
2.6666666666666665,
|
||||
3.0]
|
||||
self.assertTrue(allclose(xp, xt))
|
||||
self.assertTrue(allclose(yp, yt))
|
||||
|
||||
def test_interpolate_hermite(self):
|
||||
"""test translate_xy function"""
|
||||
# u:
|
||||
# - left side displacement to right
|
||||
# - left side rotation counterclockwise
|
||||
# - right side displacement to right
|
||||
# - right side rotation counterclockwise
|
||||
u = [ 0.012770, 0.000063, -0.002730, 0.012693, 0.000086, 0.003147]
|
||||
x, y = interpolate_hermite(u[1], u[2], u[4], u[5], scale_x=3)
|
||||
xt = [ 0. , 0.33333333, 0.66666667, 1. , 1.33333333,
|
||||
1.66666667, 2. , 2.33333333, 2.66666667, 3. ]
|
||||
yt = [ 6.30000000e-05, -7.58828532e-04, -1.39770233e-03,
|
||||
-1.84370370e-03, -2.08691495e-03, -2.11741838e-03,
|
||||
-1.92529630e-03, -1.50063100e-03, -8.33504801e-04,
|
||||
8.60000000e-05]
|
||||
self.assertTrue(allclose(x, xt))
|
||||
self.assertTrue(allclose(y, yt))
|
||||
|
||||
def test_cubics_deformation_xz(self):
|
||||
"""test cubics function with (local) deformation"""
|
||||
lns = cubics(self.global_points, deformation=self.u, rotation_plane='xz', factor=self.factor, inc=self.inc, index_offset=1)
|
||||
for l, t in zip(lns, self.test_lns_l):
|
||||
self.assertEqual(l[0], t[0]) # left point
|
||||
self.assertEqual(l[1], t[1]) # right point
|
||||
#self.assertEqual(l[2], t[2]) # deformation
|
||||
self.assertTrue(allclose(l[2], t[2]))
|
||||
plot_cubic_lines(lns, color='C3', samples=40)
|
||||
|
||||
def test_cubics_deformation_xy(self):
|
||||
"""test cubics function with (local) deformation"""
|
||||
lns = cubics(self.global_points, deformation=self.uN, rotation_plane='xy', factor=self.factor, inc=self.inc, index_offset=1)
|
||||
for l, t in zip(lns, self.test_lns_l):
|
||||
self.assertEqual(l[0], t[0]) # left point
|
||||
self.assertEqual(l[1], t[1]) # right point
|
||||
#self.assertEqual(l[2], t[2]) # deformation
|
||||
self.assertTrue(allclose(l[2], t[2]))
|
||||
plot_cubic_lines(lns, color='C3', samples=40)
|
||||
|
||||
def test_cubics_global_deformation_xz(self):
|
||||
"""test cubics function with global_deformation"""
|
||||
lns = cubics(self.global_points, global_deformation=fold_list(self.U, 3), rotation_plane='xz', factor=self.factor, inc=self.inc, index_offset=1)
|
||||
for l, t in zip(lns, self.test_lns_g):
|
||||
self.assertEqual(l[0], t[0]) # left point
|
||||
self.assertEqual(l[1], t[1]) # right point
|
||||
#self.assertEqual(l[2], t[2]) # deformation
|
||||
self.assertTrue(allclose(l[2], t[2]))
|
||||
plot_cubic_lines(lns, color='C4', samples=40)
|
||||
|
||||
def test_cubics_global_deformation_xy(self):
|
||||
"""test cubics function with global_deformation"""
|
||||
lns = cubics(self.global_points, global_deformation=fold_list(self.UN, 3), rotation_plane='xy', factor=self.factor, inc=self.inc, index_offset=1)
|
||||
for l, t in zip(lns, self.test_lns_g):
|
||||
self.assertEqual(l[0], t[0]) # left point
|
||||
self.assertEqual(l[1], t[1]) # right point
|
||||
#self.assertEqual(l[2], t[2]) # deformation
|
||||
self.assertTrue(allclose(l[2], t[2]))
|
||||
plot_cubic_lines(lns, color='C4', samples=40)
|
||||
def test_Polygon_ch_cs(self):
|
||||
# example object to rotate
|
||||
p0 = Point()
|
||||
p1 = Point(1, 0, 0)
|
||||
p2 = Point(1, 1, 1)
|
||||
p3 = Point(0, 1, 1)
|
||||
theta = math.pi/2
|
||||
test = [[0.0, 0.0, 0.0, 1], [0, 0.0, -1.0, 1], [1.0, 1.0, -1, 1],
|
||||
[1.0, 1.0, 0, 1], [0.0, 0.0, 0.0, 1]]
|
||||
|
||||
# using a coordinate system object
|
||||
pg = Polygon(p0, p1, p2, p3)
|
||||
cs = CS().rotate_y(theta)
|
||||
pg.ch_cs(cs)
|
||||
[self.assertAlmostEqual(i, j) for i, j in zip(pg.points(), test)]
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
unittest.main(verbosity=2)
|
||||
|
||||
259
tests/test_geometry2d.py
Normal file
259
tests/test_geometry2d.py
Normal file
@@ -0,0 +1,259 @@
|
||||
"""Test of geometry2d module.
|
||||
|
||||
:Date: 2019-08-20
|
||||
|
||||
.. module:: test_geometry2d
|
||||
:platform: *nix, Windows
|
||||
:synopsis: Test of geometry2d module.
|
||||
|
||||
.. moduleauthor:: Daniel Weschke <daniel.weschke@directbox.de>
|
||||
"""
|
||||
import unittest
|
||||
|
||||
import os
|
||||
import sys
|
||||
import math
|
||||
from numpy import allclose
|
||||
sys.path.insert(0, os.path.abspath('../pylib'))
|
||||
from data import fold_list
|
||||
from geometry2d import translate_xy, rotate_xy, interpolate_hermite, lines, cubics
|
||||
from geometry2d_plot import plot_lines, plot_cubic_lines
|
||||
|
||||
|
||||
class TestGeometry2d(unittest.TestCase):
|
||||
global_points = [(0, 0),
|
||||
(0, 3),
|
||||
(3, 3),
|
||||
(3, 0),
|
||||
(3, 6),
|
||||
(5, 6),
|
||||
(5, 3),
|
||||
(5, 0),
|
||||
(7, 0)]
|
||||
inc = [[1, 2],
|
||||
[2, 3],
|
||||
[4, 3],
|
||||
[3, 5],
|
||||
[5, 6],
|
||||
[6, 7],
|
||||
[7, 8],
|
||||
[9, 7]]
|
||||
|
||||
# global deformation, horizontal right, vertical down, rotation
|
||||
U = [
|
||||
0.00000, 0.00000, -5.02012,
|
||||
12.77012, 0.06333, -2.72988,
|
||||
12.69350, 0.08599, 3.14685,
|
||||
0.00000, 0.00000, -7.92017,
|
||||
-12.39817, 0.17450, 4.14446,
|
||||
-12.43490, 0.32001, -3.10697,
|
||||
-26.77684, 0.16528, 2.98214,
|
||||
0.00000, 0.00000, 0.00000,
|
||||
-26.50991, 0.00000, -1.36053,
|
||||
]
|
||||
U = [Ui/1000 for Ui in U]
|
||||
|
||||
# global deformation, only horizontal right and vertical down
|
||||
U2 = [ui for i, ui in enumerate(U) if i%3 != 2]
|
||||
|
||||
# global deformation, horizontal right, vertical up, rotation
|
||||
UN = [Ui if i%3 != 1 else -Ui for i, Ui in enumerate(U)]
|
||||
|
||||
# local deformation, horizontal right, vertical down, rotation
|
||||
u = [
|
||||
[ 0.000000, 0.000000, -0.005020, -0.000063, 0.012770, -0.002730],
|
||||
[ 0.012770, 0.000063, -0.002730, 0.012693, 0.000086, 0.003147],
|
||||
[ 0.000000, 0.000000, -0.007920, -0.000086, 0.012693, 0.003147],
|
||||
[-0.000086, 0.012693, 0.003147, -0.000175, -0.012398, 0.004144],
|
||||
[-0.012398, 0.000175, 0.004144, -0.012435, 0.000320, -0.003107],
|
||||
[ 0.000320, 0.012435, -0.003107, 0.000165, 0.026777, 0.002982],
|
||||
[ 0.000165, 0.026777, 0.002982, 0.000000, 0.000000, 0.000000],
|
||||
[ 0.014705, -0.022058, -0.001361, 0.014716, -0.022371, 0.002982],
|
||||
]
|
||||
|
||||
# local deformation, horizontal right, vertical up, rotation
|
||||
uN = [[uii if i%3 != 1 else -uii for i, uii in enumerate(ui)] for ui in u]
|
||||
|
||||
# exaggeration factor for the deformation
|
||||
factor = 20
|
||||
|
||||
# test of cubic lines
|
||||
test_lns_l = [((0, 0), (0, 3), [0.0, -0.0, -0.1004, -0.00126, -0.2554, -0.0546]),
|
||||
((0, 3), (3, 3), [0.2554, -0.00126, -0.0546, 0.25386, -0.00172, 0.06294]),
|
||||
((3, 0), (3, 3), [0.0, -0.0, -0.1584, -0.00172, -0.25386, 0.06294]),
|
||||
((3, 3), (3, 6), [-0.00172, -0.25386, 0.06294, -0.0035, 0.24796, 0.08288]),
|
||||
((3, 6), (5, 6), [-0.24796, -0.0035, 0.08288, -0.2487, -0.0064, -0.06214]),
|
||||
((5, 6), (5, 3), [0.0064, -0.2487, -0.06214, 0.0033, -0.53554, 0.05964]),
|
||||
((5, 3), (5, 0), [0.0033, -0.53554, 0.05964, 0.0, -0.0, 0.0]),
|
||||
((7, 0), (5, 3), [0.2941, 0.44116, -0.02722, 0.29432, 0.44742, 0.05964])]
|
||||
test_lns_g = [((0, 0), (0, 3), [0.0, -0.0, -0.1004024, -0.0012666, -0.2554024, -0.0545976]),
|
||||
((0, 3), (3, 3), [0.2554024, -0.0012666, -0.0545976, 0.25387, -0.0017198, 0.062937]),
|
||||
((3, 0), (3, 3), [0.0, -0.0, -0.1584034, -0.0017198, -0.25387, 0.062937]),
|
||||
((3, 3), (3, 6), [-0.0017198, -0.25387, 0.062937, -0.00349, 0.2479634, 0.0828892]),
|
||||
((3, 6), (5, 6), [-0.2479634, -0.00349, 0.0828892, -0.248698, -0.0064002, -0.0621394]),
|
||||
((5, 6), (5, 3), [0.0064002, -0.248698, -0.0621394, 0.0033056, -0.5355368, 0.0596428]),
|
||||
((5, 3), (5, 0), [0.0033056, -0.5355368, 0.0596428, 0.0, 0.0, 0.0]),
|
||||
((7, 0), (5, 3), [0.2941010455782632, 0.441151568367395, -0.0272106, 0.29431194259286797, 0.4474271690373891, 0.0596428])]
|
||||
|
||||
def test_lines(self):
|
||||
"""test lines function (undeformed structure)"""
|
||||
lns = lines(self.global_points, inc=self.inc, index_offset=1)
|
||||
test = [((0, 0), (0, 3)), ((0, 3), (3, 3)), ((3, 0), (3, 3)),
|
||||
((3, 3), (3, 6)), ((3, 6), (5, 6)), ((5, 6), (5, 3)),
|
||||
((5, 3), (5, 0)), ((7, 0), (5, 3))]
|
||||
|
||||
self.assertEqual(lns, test)
|
||||
plot_lines(lns, linestyle=':')
|
||||
|
||||
def test_lines_deformation(self):
|
||||
"""test lines function with deformation (deformed structure)"""
|
||||
lns = lines(self.global_points, deformation=fold_list(self.U2, 2), factor=self.factor, inc=self.inc, index_offset=1)
|
||||
test = [((0.0, 0.0), (0.25540240000000003, 3.0012666)), ((0.25540240000000003, 3.0012666), (3.25387, 3.0017198)), ((3.0, 0.0), (3.25387, 3.0017198)), ((3.25387, 3.0017198), (2.7520366, 6.00349)), ((2.7520366, 6.00349), (4.751302, 6.0064002)), ((4.751302, 6.0064002), (4.4644632, 3.0033056)), ((4.4644632, 3.0033056), (5.0, 0.0)), ((6.4698018, 0.0), (4.4644632, 3.0033056))]
|
||||
self.assertEqual(lns, test)
|
||||
plot_lines(lns, color='C2')
|
||||
|
||||
def test_translate_xy(self):
|
||||
"""test translate_xy function with single values"""
|
||||
x = 2
|
||||
y = 4
|
||||
xp, yp = translate_xy((0.5, 1), x, y)
|
||||
xt = 2.5
|
||||
yt = 5
|
||||
self.assertEqual(xp, xt)
|
||||
self.assertEqual(yp, yt)
|
||||
|
||||
def test_translate_xy_list(self):
|
||||
"""test translate_xy function"""
|
||||
x = [ 0. , 0.33333333, 0.66666667, 1. , 1.33333333,
|
||||
1.66666667, 2. , 2.33333333, 2.66666667, 3. ]
|
||||
y = [ 6.30000000e-05, -7.58828532e-04, -1.39770233e-03,
|
||||
-1.84370370e-03, -2.08691495e-03, -2.11741838e-03,
|
||||
-1.92529630e-03, -1.50063100e-03, -8.33504801e-04,
|
||||
8.60000000e-05]
|
||||
xp, yp = translate_xy((1, 0.001), x, y)
|
||||
xt = [1.0,
|
||||
1.3333333333333333,
|
||||
1.6666666666666665,
|
||||
2.0,
|
||||
2.333333333333333,
|
||||
2.666666666666667,
|
||||
3.0,
|
||||
3.333333333333333,
|
||||
3.6666666666666665,
|
||||
4.0]
|
||||
yt = [0.0010629999999999999,
|
||||
0.00024117146776406044,
|
||||
-0.00039770233196159102,
|
||||
-0.0008437037037037035,
|
||||
-0.0010869149519890263,
|
||||
-0.0011174183813443071,
|
||||
-0.00092529629629629624,
|
||||
-0.00050063100137174286,
|
||||
0.0001664951989026062,
|
||||
0.0010859999999999999]
|
||||
self.assertTrue(allclose(xp, xt))
|
||||
self.assertTrue(allclose(yp, yt))
|
||||
|
||||
def test_rotate_xy(self):
|
||||
"""test translate_xy function with single values"""
|
||||
x = 2
|
||||
y = 4
|
||||
xp, yp = rotate_xy((0.5, 1), math.pi/2, x, y)
|
||||
xt = -2.5
|
||||
yt = 2.5
|
||||
self.assertEqual(xp, xt)
|
||||
self.assertEqual(yp, yt)
|
||||
|
||||
def test_rotate_xy_list(self):
|
||||
"""test translate_xy function"""
|
||||
x = [ 0. , 0.33333333, 0.66666667, 1. , 1.33333333,
|
||||
1.66666667, 2. , 2.33333333, 2.66666667, 3. ]
|
||||
y = [ 6.30000000e-05, -7.58828532e-04, -1.39770233e-03,
|
||||
-1.84370370e-03, -2.08691495e-03, -2.11741838e-03,
|
||||
-1.92529630e-03, -1.50063100e-03, -8.33504801e-04,
|
||||
8.60000000e-05]
|
||||
xp, yp = rotate_xy((0, 0), math.pi/2, x, y)
|
||||
xt = [-6.3e-05,
|
||||
0.00075882853223595997,
|
||||
0.0013977023319616318,
|
||||
0.0018437037037037647,
|
||||
0.0020869149519891078,
|
||||
0.002117418381344409,
|
||||
0.0019252962962964188,
|
||||
0.0015006310013718858,
|
||||
0.0008335048010975571,
|
||||
-8.5999999999816312e-05]
|
||||
yt = [3.8576374173141622e-21,
|
||||
0.33333333333333331,
|
||||
0.66666666666666663,
|
||||
1.0,
|
||||
1.3333333333333333,
|
||||
1.6666666666666667,
|
||||
2.0,
|
||||
2.333333333333333,
|
||||
2.6666666666666665,
|
||||
3.0]
|
||||
self.assertTrue(allclose(xp, xt))
|
||||
self.assertTrue(allclose(yp, yt))
|
||||
|
||||
def test_interpolate_hermite(self):
|
||||
"""test translate_xy function"""
|
||||
# u:
|
||||
# - left side displacement to right
|
||||
# - left side rotation counterclockwise
|
||||
# - right side displacement to right
|
||||
# - right side rotation counterclockwise
|
||||
u = [ 0.012770, 0.000063, -0.002730, 0.012693, 0.000086, 0.003147]
|
||||
x, y = interpolate_hermite(u[1], u[2], u[4], u[5], scale_x=3)
|
||||
xt = [ 0. , 0.33333333, 0.66666667, 1. , 1.33333333,
|
||||
1.66666667, 2. , 2.33333333, 2.66666667, 3. ]
|
||||
yt = [ 6.30000000e-05, -7.58828532e-04, -1.39770233e-03,
|
||||
-1.84370370e-03, -2.08691495e-03, -2.11741838e-03,
|
||||
-1.92529630e-03, -1.50063100e-03, -8.33504801e-04,
|
||||
8.60000000e-05]
|
||||
self.assertTrue(allclose(x, xt))
|
||||
self.assertTrue(allclose(y, yt))
|
||||
|
||||
def test_cubics_deformation_xz(self):
|
||||
"""test cubics function with (local) deformation"""
|
||||
lns = cubics(self.global_points, deformation=self.u, rotation_plane='xz', factor=self.factor, inc=self.inc, index_offset=1)
|
||||
for l, t in zip(lns, self.test_lns_l):
|
||||
self.assertEqual(l[0], t[0]) # left point
|
||||
self.assertEqual(l[1], t[1]) # right point
|
||||
#self.assertEqual(l[2], t[2]) # deformation
|
||||
self.assertTrue(allclose(l[2], t[2]))
|
||||
plot_cubic_lines(lns, color='C3', samples=40)
|
||||
|
||||
def test_cubics_deformation_xy(self):
|
||||
"""test cubics function with (local) deformation"""
|
||||
lns = cubics(self.global_points, deformation=self.uN, rotation_plane='xy', factor=self.factor, inc=self.inc, index_offset=1)
|
||||
for l, t in zip(lns, self.test_lns_l):
|
||||
self.assertEqual(l[0], t[0]) # left point
|
||||
self.assertEqual(l[1], t[1]) # right point
|
||||
#self.assertEqual(l[2], t[2]) # deformation
|
||||
self.assertTrue(allclose(l[2], t[2]))
|
||||
plot_cubic_lines(lns, color='C3', samples=40)
|
||||
|
||||
def test_cubics_global_deformation_xz(self):
|
||||
"""test cubics function with global_deformation"""
|
||||
lns = cubics(self.global_points, global_deformation=fold_list(self.U, 3), rotation_plane='xz', factor=self.factor, inc=self.inc, index_offset=1)
|
||||
for l, t in zip(lns, self.test_lns_g):
|
||||
self.assertEqual(l[0], t[0]) # left point
|
||||
self.assertEqual(l[1], t[1]) # right point
|
||||
#self.assertEqual(l[2], t[2]) # deformation
|
||||
self.assertTrue(allclose(l[2], t[2]))
|
||||
plot_cubic_lines(lns, color='C4', samples=40)
|
||||
|
||||
def test_cubics_global_deformation_xy(self):
|
||||
"""test cubics function with global_deformation"""
|
||||
lns = cubics(self.global_points, global_deformation=fold_list(self.UN, 3), rotation_plane='xy', factor=self.factor, inc=self.inc, index_offset=1)
|
||||
for l, t in zip(lns, self.test_lns_g):
|
||||
self.assertEqual(l[0], t[0]) # left point
|
||||
self.assertEqual(l[1], t[1]) # right point
|
||||
#self.assertEqual(l[2], t[2]) # deformation
|
||||
self.assertTrue(allclose(l[2], t[2]))
|
||||
plot_cubic_lines(lns, color='C4', samples=40)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user