Class Definition: geom.UCS

drafting: geom.UCS

A user coordinate system: an origin, an x axis and a normal, defining a plane with coordinates of its own.

A geom.UCS is where a geom.Polyline or a geom.Region lies: its vertices are coordinates in the UCS, and a solid made from a region is made where its UCS puts it. A region drawn in the default UCS, the world xy plane, is laid on the face of a part by giving it a UCS on that face, which is what a CAD program’s user coordinate system is for.

It is a coordinate system, not only a plane: two systems on the same plane with different origins or x axes place the same outline differently, and solid.revolve turns about the y axis through the origin. The y axis is the normal crossed with the x axis, so the axes are right-handed.

A UCS is made by its constructor, from a normal and points or with the mouse in a viewer, or by geom.UCS.threepoint from three points. It is a value and never changes.

See also: geom.Polyline, geom.Region, model.Viewer.pickucs

Source Code: geom.UCS

The geom.UCS class contains the following properties:

The origin, a 1-by-3 point in world coordinates.

The unit x axis, a 1-by-3 direction in world coordinates.

The unit normal of the plane, its z axis.

The unit y axis, the normal crossed with the x axis.

The geom.UCS class offers the following public methods:

geom.UCS: U = geom.UCS ()

geom.UCS: U = geom.UCS (V)

geom.UCS: U = geom.UCS (V, MODE)

geom.UCS: U = geom.UCS (NORMAL, ORIGIN)

geom.UCS: U = geom.UCS (NORMAL, ORIGIN, XPOINT)

U = geom.UCS () returns the world coordinate system: the xy plane, with its origin at the world origin.

U = geom.UCS (V) picks one with the mouse in the viewer V, a model.Viewer showing a shape: a flat face and two points for the axes, then the origin. With MODE 'points' three points give the axes instead of a face and two. See model.Viewer.pickucs.

U = geom.UCS (NORMAL, ORIGIN, XPOINT) lays the plane square to the direction NORMAL through the point ORIGIN, its origin, with its x axis pointing from ORIGIN towards the point XPOINT. XPOINT need not lie on the plane: the direction is projected onto it, so any point along an edge of the part will do. It must not lie on the normal through ORIGIN, which gives no direction in the plane.

U = geom.UCS (NORMAL, ORIGIN) takes the x axis from the normal alone by DXF’s arbitrary axis algorithm, so it means the same here as in a DXF file. When the normal is within about a degree of the world z axis, x is the world y axis crossed with the normal: the world x axis for a plane facing up, its reverse for one facing down. Otherwise x is the world z axis crossed with the normal, which is level and runs to the right as the plane is seen from the side its normal faces, so that y points up the plane.

Points and directions are 3-element vectors in world coordinates, and directions need not have unit length. The y axis is the normal crossed with the x axis. What is plainly residue of floating-point arithmetic is taken as zero: an axis component below 1e-12, and an origin coordinate below 1e-12 of the origin’s size, so that a corner picked at [0, 0, 40] is not kept as [-3.6e-15, 0, 40].

 
 ## The front face of a block, facing -y, origin at its lower left
 ## corner, x along the bottom edge
 U = geom.UCS ([0, -1, 0], [0, 0, 0], [80, 0, 0]);
 U.YAxis
 ⇒ 0   0   1

geom.UCS: U = geom.UCS.threepoint (P1, P2, P3)

U = geom.UCS.threepoint (P1, P2, P3) returns the UCS whose origin is P1, whose x axis runs from P1 towards P2, and whose y axis lies in the plane of the three points on the side of P3, as AutoCAD’s three-point UCS is defined. Each point is a 3-element vector in world coordinates, and the three must not lie on one line.

geom.UCS: TF = eq (U1, U2)

TF = eq (U1, U2), or U1 == U2, is true when the two have the same origin, x axis and normal, exactly. Two systems on one plane with different origins or x axes are not the same.

geom.UCS: W = toworld (U, P)

W = toworld (U, P) returns, as an N-by-3 matrix, the world coordinates of the points whose coordinates in U are the rows of P, an N-by-2 matrix of points in the plane or an N-by-3 matrix with their heights above it.

See also: geom.UCS.tolocal

geom.UCS: P = tolocal (U, W)

P = tolocal (U, W) returns, as an N-by-3 matrix, the coordinates in U of the points whose world coordinates are the rows of the N-by-3 matrix W: their x and y in the plane and their height above it.

See also: geom.UCS.toworld