File: test_610_ocs.py

package info (click to toggle)
ezdxf 1.4.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 104,528 kB
  • sloc: python: 182,341; makefile: 116; lisp: 20; ansic: 4
file content (103 lines) | stat: -rw-r--r-- 3,068 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# Copyright (c) 2018 Manfred Moitzi
# License: MIT License
"""
CIRCLE    Layer: "LAYER-5"
Color: 5 (blue)    Linetype: "BYLAYER"
center point, (-9.56460754, 8.44764172, 9.97894327)

CIRCLE    Layer: "LAYER-4"
Color: 4 (cyan)    Linetype: "BYLAYER"
center point, (-1.60085321, 9.29648008, 1.85322122)

CIRCLE    Layer: "LAYER-3"
Color: 3 (green)    Linetype: "BYLAYER"
center point, (-3.56027455, 9.08762984, 3.85249348)

CIRCLE    Layer: "LAYER-2"
Color: 2 (yellow)    Linetype: "BYLAYER"
center point, (-5.53851623, 8.87677359, 5.87096886)

Extrusion direction relative to UCS: X=0.70819791  Y=0.07548520  Z=0.70196702

"""
from ezdxf.math import OCS, Matrix44, Vec3

EXTRUSION = (0.7081979129501316, 0.0754851955385861, 0.7019670229772758)


def is_close_points(p1, p2, places=6):
    for v1, v2 in zip(p1, p2):
        if not round(v1, places) == round(v2, places):
            return False
    return True


def test_wcs_to_ocs():
    ocs = OCS(EXTRUSION)
    assert is_close_points(
        ocs.from_wcs((-9.56460754, 8.44764172, 9.97894327)),
        (9.41378764657076, 13.15481838975576, 0.8689258932616031),
        places=6,
    )
    assert is_close_points(
        ocs.from_wcs((-1.60085321, 9.29648008, 1.85322122)),
        (9.41378764657076, 1.745643639268379, 0.8689258932616031),
        places=6,
    )
    assert is_close_points(
        ocs.from_wcs((-3.56027455, 9.08762984, 3.85249348)),
        (9.41378764657076, 4.552784531093068, 0.8689258932616031),
        places=6,
    )
    assert is_close_points(
        ocs.from_wcs((-5.53851623, 8.87677359, 5.87096886)),
        (9.41378764657076, 7.386888158025531, 0.8689258932616031),
        places=6,
    )


def test_ocs_to_wcs():
    ocs = OCS(EXTRUSION)
    wcs = ocs.to_wcs((9.41378764657076, 13.15481838975576, 0.8689258932616031))
    assert is_close_points(
        wcs,
        (-9.56460754, 8.44764172, 9.97894327),
        places=6,
    )
    assert is_close_points(
        ocs.to_wcs((9.41378764657076, 1.745643639268379, 0.8689258932616031)),
        (-1.60085321, 9.29648008, 1.85322122),
        places=6,
    )
    assert is_close_points(
        ocs.to_wcs((9.41378764657076, 4.552784531093068, 0.8689258932616031)),
        (-3.56027455, 9.08762984, 3.85249348),
        places=6,
    )
    assert is_close_points(
        ocs.to_wcs((9.41378764657076, 7.386888158025531, 0.8689258932616031)),
        (-5.53851623, 8.87677359, 5.87096886),
        places=6,
    )


def test_matrix44_to_ocs():
    ocs = OCS(EXTRUSION)
    matrix = Matrix44.ucs(ocs.ux, ocs.uy, ocs.uz)
    assert is_close_points(
        matrix.ocs_from_wcs(Vec3(-9.56460754, 8.44764172, 9.97894327)),
        (9.41378764657076, 13.15481838975576, 0.8689258932616031),
        places=6,
    )


def test_matrix44_to_wcs():
    ocs = OCS(EXTRUSION)
    matrix = Matrix44.ucs(ocs.ux, ocs.uy, ocs.uz)
    assert is_close_points(
        matrix.ocs_to_wcs(
            Vec3(9.41378764657076, 13.15481838975576, 0.8689258932616031)
        ),
        (-9.56460754, 8.44764172, 9.97894327),
        places=6,
    )