The UCS object uses the origin, X-axis direction, and Y-axis direction properties to define the position and orientation of the user coordinate system. In the examples below, the pUCS variable stores the pointer to the UCS record object.
The property defines the three-dimensional vector specifying the direction of the X-axis of the user coordinate system in the world coordinate system. The X-vector has the value (1,0,0) by default and coincides with the WCS X-axis.
To get the X-axis direction, use the xAxis() method which does not have arguments and returns the three-dimensional vector as an instance of the OdGeVector3d type. For example:
OdGeVector3d vector = pUCS->xAxis();
odPrintConsoleString(L"\nUCS X-axis = (%f,%f,%f)", vector.x, vector.y, vector.z);
To set the X-axis direction, use the setXAxis() method which requires one argument — the three-dimensional vector as an OdGeVector3d instance — and does not return a value. For example:
OdGeVector3d vector(0.301, 0.707, 0.105);
pUCS->setXAxis(vector);
The property defines the three-dimensional vector specifying the direction of the Y-axis of the user coordinate system in the world coordinate system. The Y-vector has the value (0,1,0) by default and coincides with WCS Y-axis.
To get the Y-axis direction, use the yAxis() method which does not have arguments and returns the three-dimensional vector as an instance of the OdGeVector3d type. For example:
OdGeVector3d vector = pUCS->yAxis();
odPrintConsoleString(L"\nUCS Y-axis = (%f,%f,%f)", vector.x, vector.y, vector.z);
To set the Y-axis direction, use the setYAxis() method which requires one argument — the three-dimensional vector as an OdGeVector3d instance — and does not return a value. For example:
OdGeVector3d vector(0.105, 0.301, 0.707);
pUCS->setYAxis(vector);
There is no property for storing the Z-axis. Since a user coordinate system is an orthogonal system, the Z-axis vector can be calculated as a cross product of X- and Y-axes:
OdGeVector3d zAxis = pUCS->xAxis().crossProduct(pUCS->yAxis());
odPrintConsoleString(L"\nUCS Z-axis = (%f,%f,%f)", zAxis.x, zAxis.y, zAxis.z);
The property defines the three-dimensional coordinates of the origin of the user coordinate system relative to the origin of the world coordinate system. The origin has the value (0,0,0) by default and coincides with the WCS origin.
To get the origin, use the origin() method which does not have arguments and returns the three-dimensional point as an instance of the OdGePoint3d type. For example:
OdGePoint3d point = pUCS->origin();
odPrintConsoleString(L"\nUCS Origin = (%f,%f,%f)", point.x, point.y, point.z);
To set the origin, use the setOrigin() method which requires one argument — the three-dimensional point as an instance of the OdGePoint3d type — and does not return a value. For example:
OdGePoint3d point(10, 30, 20);
pUCS->setOrigin(point);
The property defines the three-dimensional coordinates of the base origin of the user coordinate system relative to the origin of the world coordinate system for the specified orthographic view. The setOrigin() method sets all orthographic view origins to the specified value.
To get the base origin, use the ucsBaseOrigin() method which requires one argument — the orthographic view identifier as a value of the OdDb::OrthographicView enumeration — and returns the three-dimensional point as an instance of the OdGePoint3d type. For example:
OdGePoint3d point = pUCS->ucsBaseOrigin(OdDb::kTopView);
odPrintConsoleString(L"\nUCS Base Origin = (%f,%f,%f)", point.x, point.y, point.z);
To set the base origin, use the setUcsBaseOrigin() method which requires two arguments — the three-dimensional point as an OdGePoint3d instance and the orthographic view identifier as an OrthographicView number — and does not return a value. For example:
OdGePoint3d point(4, 6, 2);
pUCS->setUcsBaseOrigin(point, OdDb::kTopView);
The UCS base origin point and vectors of X-, Y- and Z-axes define the matrix of the user coordinate system that can be used to transform the coordinates from UCS to WCS.
For example, to get WCS coordinates of the point defined in the user coordinate system:
OdGePoint3d ucsOrigin = pUCS->origin();
OdGeVector3d ucsXAxis = pUCS->xAxis();
OdGeVector3d ucsYAxis = pUCS->yAxis();
OdGeMatrix3d ucsMatrix;
ucsMatrix.setCoordSystem(ucsOrigin, ucsXAxis, ucsYAxis, ucsXAxis.crossProduct(ucsYAxis));
ucsPoint.transformBy(ucsMatrix);
To get a WCS copy of the UCS point, multiply the user coordinate system matrix by the UCS point:
OdGePoint3d wcsPoint = ucsMatrix * ucsPoint;
To get UCS coordinates of the point defined in the world coordinate system, the inverted UCS matrix is used:
wcsPoint.transformBy(ucsMatrix.invert());
To get a UCS copy of the WCS point, multiply the inverted user coordinate system matrix by the WCS point:
OdGePoint3d ucsPoint = ucsMatrix.invert() * wcsPoint;
Working with Basic Geometry Types
Example of Working with the UCS Record Object
Copyright © 2002 – 2021. Open Design Alliance. All rights reserved.
|