File: ocs.rst

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 (139 lines) | stat: -rw-r--r-- 4,941 bytes parent folder | download
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
.. _Object Coordinate System:

Object Coordinate System (OCS)
==============================


- `DXF Reference for OCS`_ provided by Autodesk.

The points associated with each entity are expressed in terms of the entity's
own object coordinate system (OCS). The OCS was referred to as ECS in previous
releases of AutoCAD.

With OCS, the only additional information needed to describe the entity's
position in 3D space is the 3D vector describing the z-axis of the OCS (often
referenced as extrusion vector), and the elevation value, which is the
distance of the entity xy-plane to the WCS/OCS origin.

For a given z-axis (extrusion) direction, there are an infinite number of
coordinate systems, defined by translating the origin in 3D space and by
rotating the x- and y-axis around the z-axis. However, for the same z-axis
direction, there is only one OCS. It has the following properties:

- Its origin coincides with the WCS origin.
- The orientation of the x- and y-axis within the xy-plane are calculated in an
  arbitrary but consistent manner. AutoCAD performs this calculation using the
  arbitrary axis algorithm (see below).
- Because of the `Arbitrary Axis Algorithm`_ the OCS can only represent a
  **right-handed** coordinate system!

The following entities do not lie in a particular plane. All points are
expressed in world coordinates. Of these entities, only lines and points can be
extruded. Their extrusion direction can differ from the world z-axis.

- :class:`~ezdxf.entities.Line`
- :class:`~ezdxf.entities.Point`
- :class:`~ezdxf.entities.3DFace`
- :class:`~ezdxf.entities.Polyline` (3D)
- :class:`~ezdxf.entities.Vertex` (3D)
- :class:`~ezdxf.entities.Polymesh`
- :class:`~ezdxf.entities.Polyface`
- :class:`~ezdxf.entities.Viewport`

These entities are planar in nature. All points are expressed in object
coordinates. All of these entities can be extruded. Their extrusion direction
can differ from the world z-axis.

- :class:`~ezdxf.entities.Circle`
- :class:`~ezdxf.entities.Arc`
- :class:`~ezdxf.entities.Solid`
- :class:`~ezdxf.entities.Trace`
- :class:`~ezdxf.entities.Text`
- :class:`~ezdxf.entities.Attrib`
- :class:`~ezdxf.entities.Attdef`
- :class:`~ezdxf.entities.Shape`
- :class:`~ezdxf.entities.Insert`
- :class:`~ezdxf.entities.Polyline` (2D)
- :class:`~ezdxf.entities.Vertex` (2D)
- :class:`~ezdxf.entities.LWPolyline`
- :class:`~ezdxf.entities.Hatch`
- :class:`~ezdxf.entities.Image`

Some of a :class:`~ezdxf.entities.Dimension`'s points are expressed in WCS and
some in OCS.

Elevation
---------

Elevation group code 38:

Exists only in output from versions prior to R11. Otherwise, Z coordinates are
supplied as part of each of the entity's defining points.

.. _Arbitrary Axis Algorithm:

Arbitrary Axis Algorithm
------------------------

- `DXF Reference for Arbitrary Axis Algorithm`_ provided by Autodesk.

The arbitrary axis algorithm is used by AutoCAD internally to implement the
arbitrary but consistent generation of object coordinate systems for all
entities that use object coordinates.

Given a unit-length vector to be used as the z-axis of a coordinate system, the
arbitrary axis algorithm generates a corresponding x-axis for the coordinate
system. The y-axis follows by application of the **right-hand** rule.

We are looking for the arbitrary x- and y-axis to go with the normal Az
(the arbitrary z-axis). They will be called Ax and Ay (using
:class:`~ezdxf.math.Vec3`):

.. code-block:: python

    Az = Vec3(entity.dxf.extrusion).normalize()  # normal (extrusion) vector
    if (abs(Az.x) < 1/64.) and (abs(Az.y) < 1/64.):
         Ax = Vec3(0, 1, 0).cross(Az).normalize()  # the cross-product operator
    else:
         Ax = Vec3(0, 0, 1).cross(Az).normalize()  # the cross-product operator
    Ay = Az.cross(Ax).normalize()


WCS to OCS
----------

.. code-block:: python

    def wcs_to_ocs(point):
        px, py, pz = Vec3(point)  # point in WCS
        x = px * Ax.x + py * Ax.y + pz * Ax.z
        y = px * Ay.x + py * Ay.y + pz * Ay.z
        z = px * Az.x + py * Az.y + pz * Az.z
        return Vec3(x, y, z)

OCS to WCS
----------

.. code-block:: python

    Wx = wcs_to_ocs((1, 0, 0))
    Wy = wcs_to_ocs((0, 1, 0))
    Wz = wcs_to_ocs((0, 0, 1))

    def ocs_to_wcs(point):
        px, py, pz = Vec3(point)  # point in OCS
        x = px * Wx.x + py * Wx.y + pz * Wx.z
        y = px * Wy.x + py * Wy.y + pz * Wy.z
        z = px * Wz.x + py * Wz.y + pz * Wz.z
        return Vec3(x, y, z)

.. seealso::

    - :class:`ezdxf.math.OCS` management class
    - The :meth:`ezdxf.entities.DXFGraphic.ocs` method returns the :class:`~ezdxf.math.OCS`
      of a graphical DXF entity.
    - :ref:`tut_ocs`

.. _DXF Reference for OCS: https://help.autodesk.com/view/OARX/2018/ENU/?guid=GUID-D99F1509-E4E4-47A3-8691-92EA07DC88F5

.. _DXF Reference for Arbitrary Axis Algorithm: https://help.autodesk.com/view/OARX/2018/ENU/?guid=GUID-E19E5B42-0CC7-4EBA-B29F-5E1D595149EE