add issequence function to data and plot functions and examples for geometry

This commit is contained in:
2019-12-26 10:56:33 +01:00
parent 3be9e2f20f
commit 4b42d7b508
49 changed files with 2845 additions and 628 deletions

View File

@@ -12,8 +12,8 @@ import unittest
import os
import sys
sys.path.insert(0, os.path.abspath('../pylib'))
from data import read, unique_ending, get_id, seq
sys.path.insert(0, os.path.abspath('..'))
from pylib.data import read, unique_ending, get_id, seq
class TestData(unittest.TestCase):

View File

@@ -13,9 +13,9 @@ import unittest
import os
import sys
from pylab import array, argmax, subplot, plot, title, xlim, show, gradient, linspace
sys.path.insert(0, os.path.abspath('../pylib'))
from data import data_read
from numerical.fit import gauss_fit
sys.path.insert(0, os.path.abspath('..'))
from pylib.data import read
from pylib.numerical.fit import gauss_fit
class TestFit(unittest.TestCase):
@@ -23,7 +23,7 @@ class TestFit(unittest.TestCase):
def test_gauss(self):
"""test function"""
file_name = "test_fit.dat"
x, y = data_read(file_name, 3, 2)
x, y = read(file_name, 3, 2)
subplot(2, 2, 1)
plot(x, y, '.-')

View File

@@ -13,69 +13,85 @@ import unittest
import os
import sys
import math
sys.path.insert(0, os.path.abspath('../pylib'))
from mathematics import vector
from geometry import Direction, Point, CS, Wireframe, Polygon
sys.path.insert(0, os.path.abspath('..'))
from pylib.geometry import Direction, Point, CS, Wireframe, Line, Polygon, Circle
class TestGeometry(unittest.TestCase):
def test_Direction(self):
p = Direction()
self.assertIsInstance(
p, list)
p,
list)
self.assertEqual(
p, [1, 0, 0, 0])
p,
[1, 0, 0, 0])
self.assertEqual(
Direction(2, 3, 4), [2, 3, 4, 0])
Direction(2, 3, 4),
[2, 3, 4, 0])
self.assertIsInstance(
p, vector)
def test_Direction_getitem(self):
self.assertEqual(
p, vector([1, 0, 0, 0]))
Direction()[:3],
[1, 0, 0])
self.assertEqual(
Direction(2, 3, 4), vector([2, 3, 4, 0]))
def test_Direction_xyz(self):
self.assertEqual(
Direction().xyz(), [1, 0, 0])
self.assertEqual(
Direction(1, -1, 1).xyz(), [1, -1, 1])
Direction(1, -1, 1)[:3],
[1, -1, 1])
def test_Point(self):
p = Point()
self.assertIsInstance(
p, list)
p,
list)
self.assertEqual(
p, [0, 0, 0, 1])
p,
[0, 0, 0, 1])
self.assertEqual(
Point(2, 3, 4), [2, 3, 4, 1])
Point(2, 3, 4),
[2, 3, 4, 1])
self.assertIsInstance(
p, vector)
def test_Point_getitem(self):
self.assertEqual(
p, vector([0, 0, 0, 1]))
Point()[:3],
[0, 0, 0])
self.assertEqual(
Point(2, 3, 4), vector([2, 3, 4, 1]))
Point(1, -1, 1)[:3],
[1, -1, 1])
def test_Point_xyz(self):
def test_Point_rotate(self):
[self.assertAlmostEqual(i, j) for i, j in
zip(Point(1, 1, 1).rotate_x(math.pi/4), [1, 0, 1.414213562373095, 1])]
def test_CS(self):
self.assertEqual(
Point().xyz(), [0, 0, 0])
self.assertEqual(
Point(1, -1, 1).xyz(), [1, -1, 1])
CS(),
[[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]])
def test_CS_rotate(self):
[self.assertAlmostEqual(k, l) for i, j in
zip(CS().rotate_y(-math.pi/2),
[[0, 0.0, -1.0, 0.0], [0, 1, 0, 0], [1.0, 0.0, 0, 0.0], [0, 0, 0, 1]])
for k, l in zip(i, j)]
def test_Wireframe(self):
self.assertEqual(
Wireframe().points(), [])
Wireframe().points(),
[])
# 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(), [[]])
Wireframe([]).points(),
[[]])
self.assertEqual(
Wireframe(Point()).points(), [[0, 0, 0, 1]])
Wireframe(Point()).points(),
[[0, 0, 0, 1]])
def test_Line(self):
self.assertEqual(
Wireframe(Point()).points(), [vector([0, 0, 0, 1])])
Line().points(),
[[-1, 0, 0, 1], [1, 0, 0, 1]])
def test_Polygon(self):
p0 = Point()
@@ -87,6 +103,14 @@ class TestGeometry(unittest.TestCase):
pg.points(),
[[0, 0, 0, 1], [1, 0 , 0, 1], [1, 1, 1, 1], [0, 1, 1, 1], [0, 0, 0, 1]])
def test_Polygon_rotate(self):
pg = Polygon(Point(1, 1, 1)).rotate_x(math.pi/4)
[self.assertAlmostEqual(i, j) for i, j in
zip(pg.points()[0], [1, 0, 1.414213562373095, 1])]
[self.assertAlmostEqual(k, l) for i, j in
zip(pg.xyz(), ((1, 1), (0, 0), (1.414213562373095, 1.414213562373095)))
for k, l in zip(i, j)]
def test_Polygon_ch_cs(self):
# example object to rotate
p0 = Point()
@@ -103,5 +127,23 @@ class TestGeometry(unittest.TestCase):
pg.ch_cs(cs)
[self.assertAlmostEqual(i, j) for i, j in zip(pg.points(), test)]
def test_Circle(self):
cs = Circle(n=4).points()
test = [[1, 0, 0, 1], [0, 1, 0, 1], [-1, 0, 0, 1], [0, -1, 0 ,1], [1, 0, 0, 1]]
[self.assertAlmostEqual(i, j) for i, j in zip(cs, test)]
cs = Circle().points()
test = [[1.0, 0.0, 0, 1],
[0.8090169943749475, 0.5877852522924731, 0, 1],
[0.30901699437494745, 0.9510565162951535, 0, 1],
[-0.30901699437494734, 0.9510565162951536, 0, 1],
[-0.8090169943749473, 0.5877852522924732, 0, 1],
[-1.0, 1.2246467991473532e-16, 0, 1],
[-0.8090169943749476, -0.587785252292473, 0, 1],
[-0.30901699437494756, -0.9510565162951535, 0, 1],
[0.30901699437494723, -0.9510565162951536, 0, 1],
[0.8090169943749473, -0.5877852522924734, 0, 1]]
[self.assertAlmostEqual(k, l) for i, j in zip(cs, test) for k, l in zip(i, j) ]
if __name__ == '__main__':
unittest.main(verbosity=2)

View File

@@ -14,10 +14,10 @@ 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
sys.path.insert(0, os.path.abspath('..'))
from pylib.data import fold_list
from pylib.geometry2d import translate_xy, rotate_xy, interpolate_hermite, lines, cubics
from pylib.geometry2d_plot import plot_lines, plot_cubic_lines
class TestGeometry2d(unittest.TestCase):

View File

@@ -12,10 +12,10 @@ import unittest
import os
import sys
sys.path.insert(0, os.path.abspath('../pylib'))
sys.path.insert(0, os.path.abspath('..'))
import math
from mathematics import vector, matrix
from pylib.mathematics import vector, matrix
class TestGeometry(unittest.TestCase):

View File

@@ -19,10 +19,10 @@ from matplotlib.pyplot import figure, subplots, plot, show
import os
import sys
sys.path.insert(0, os.path.abspath('../pylib'))
from numerical.ode import (e1, e2, e4, i1, newmark_newtonraphson,
newmark_newtonraphson_rdk)
from numerical.ode_model import disk, disk_nm, disk_nmmdk
sys.path.insert(0, os.path.abspath('..'))
from pylib.numerical.ode import (e1, e2, e4, i1,
newmark_newtonraphson, newmark_newtonraphson_rdk)
from pylib.numerical.ode_model import disk, disk_nm, disk_nmmdk
def plotx1rphi(x, t, title):
"""Plot plane rotation (x, y, phi)

View File

@@ -14,8 +14,8 @@ from time import mktime
import os
import sys
sys.path.insert(0, os.path.abspath('../pylib'))
from time_of_day import (in_seconds, seconds, seconds_norm,
sys.path.insert(0, os.path.abspath('..'))
from pylib.time_of_day import (in_seconds, seconds, seconds_norm,
minutes, minutes_norm, hours, hours_norm, days, days_norm,
transform)