You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The OCS is defined by the extrusion vector and an elevation value.
The default OCS is defined by an extrusion vector of (0, 0, 1), that means the extrusion vector is aligned to the WCS z-axis and the OCS is coincident with the WCS, in simpler words: OCS coordinates are WCS coordinates.
Always compare 3D vectors by the isclose() method of the Vec3 class:
fromezdxf.mathimportZ_AXISifnotZ_AXIS.isclose(arc.dxf.extrusion):
# this entity has not WCS coordinates
...
When should you care about OCS coordinates?
When the extrusion vector Arc.dxf.extrusion is (0, 0, -1) you are dealing with an inverted OCS.
Even pure 2D drawings can contain inverted OCS as a result of mirror operations.
ezdxf has a special module called upright to flip inverted OCS and align them with the WCS.
fromezdxfimportuprightupright.upright(entity) # orupright.upright_all(msp) # to apply the function to all entities in a collection
The function can be called on any entity, even multiple times, without raising an error - only inverted OCS will be flipped.
The extrusion vector should be (0, 0, 1) now and the OCS is aligned with the WCS.
Text based entity types can not be flipped!
In all other cases you have to convert OCS coordinates to WCS coordinates:
ocs=arc.ocs()
wcs_center=ocs.to_wcs(arc.dxf.center) # center.z defines the elevation
The start- and end angles of the arc are counter-clockwise oriented around the OCS z-axis (extrusion vector) and starting at the OCS x-axis defined by the Arbitrary Axis Algorithm.
A point on ARC calculation is done in OCS coordinates and converted to WCS coordinates:
importmathfromezdxf.mathimportVec3radius=arc.dxf.radiuscenter=Vec3(arc.dxf.center) # center.z defines the elevationangle=arc.dxf.start_angle# in degreesocs_point=center+Vec3.from_deg_angle(angle, radius)
ocs=arc.ocs()
wcs_point=ocs.to_wcs(ocs_point)
Using a Path object
A different solution is to convert linear entities (Line, ARC, LWPOLYLINE, ...) to a Path object:
fromezdxfimportpathp=path.make_path(arc)
ARC and ELLIPSE entities are approximated by multiple cubic Bézier-curves, which
are close enough for display rendering.
A Path has WCS coordinates and can be flattened into points (vertices).
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
It's the OCS
ARC
and other 2D entities are located in the Object Coordinate SystemOCS
.OCS
is used to place 2D entities in 3D space.OCS
can be found here.OCS
is defined by the extrusion vector and an elevation value.OCS
is defined by an extrusion vector of (0, 0, 1), that means the extrusion vector is aligned to theWCS
z-axis and theOCS
is coincident with theWCS
, in simpler words:OCS
coordinates areWCS
coordinates.isclose()
method of theVec3
class:When should you care about OCS coordinates?
When the extrusion vector
Arc.dxf.extrusion
is (0, 0, -1) you are dealing with an invertedOCS
.OCS
as a result of mirror operations.ezdxf
has a special module called upright to flip invertedOCS
and align them with theWCS
.OCS
will be flipped.OCS
is aligned with theWCS
.In all other cases you have to convert
OCS
coordinates toWCS
coordinates:OCS
z-axis (extrusion vector) and starting at theOCS
x-axis defined by theArbitrary Axis Algorithm
.ARC
calculation is done inOCS
coordinates and converted toWCS
coordinates:Using a Path object
A different solution is to convert linear entities (
Line
,ARC
,LWPOLYLINE
, ...) to aPath
object:ARC
andELLIPSE
entities are approximated by multiple cubic Bézier-curves, whichare close enough for display rendering.
Path
hasWCS
coordinates and can be flattened into points (vertices).Documentation
Beta Was this translation helpful? Give feedback.
All reactions