More often than not , in any CAD application user is given a choice to create its own coordinate System and he works relative to his own created UCS but System translate all UCS Points into WCS for internal calculation like drawing an entity.

Lets take an example to get this thing clear .

User is working on a big file say where : All dimension can be anything say in meters

X extends between -400 to 400

Y extends between -400 to 400

Z extends between 0 to 400

Now he wants to draw a Circle of Radius 50 whose center is at (100,100,100 )

and circle is drawn in XY plane .

And inside the circle he wants to place some more Objects so for sake of convince

he would like to have a UCS at circle center so that he can specify points with respect

to circle center .But System will draw these points in WCS in which whole drawing is specified .

To define a New Coordinate System we need UCS Origin Point and two Orthogonal Axis say

X Axis and Y Axis and Z will get defined by taking crossproduct X cross Y

UCS X and Y axis can be any direction depending on User requirement as in which plane he wants to work on . In our simplistic case User X and Y axis coincide with System X and Y axis.

So parameters that user need to create a UCS at Center are

1) UCS Origin : (100,100,0)

2) X Axis Vector : (1,0,0)

3) Y Axis Vector : (0,1,0)

And thats it now we have sufficient Input to create an UCS

So Here is Small UCS Class which have utility methods like converting WCS Point to UCS and vice versa

————————————————————————————————

import javax.vecmath.Matrix4f;

import javax.vecmath.Point3f;

import javax.vecmath.Vector3f;

/**

*

* @author ksingh2

*

*/

public class UcsCoordinates {

private boolean isUcsSet;

private Point3f ucsCentre=new Point3f();

private Point3f ucsPoint=new Point3f();

private Vector3f ucsXAxis=new Vector3f();

private Vector3f ucsYAxis=new Vector3f();

private Vector3f ucsZAxis=new Vector3f();

private Matrix4f wcsToUcs=new Matrix4f();

private Matrix4f ucsToWcs=new Matrix4f();

/**

* Give Point in UCS corresoponding to

* WCS Point

* @param node

* @param canvas

*/

public Point3f getUcsCordinates(Point3f wcsPoint ) {

ucsPoint.set(wcsPoint);

wcsToUcs.transform(ucsPoint);

return ucsPoint;

}

/**

*Give Point in WCS corresoponding to

* UCS Point

* @param node

* @param canvas

*/

public Point3f getWcsCordinates(Point3f ucsPoint ) {

ucsPoint.set(ucsPoint);

ucsToWcs.transform(ucsPoint);

return ucsPoint;

}

/**

*

* @param originPoint

* @param yAxis

* @param xAxis

*/

public UcsCoordinates(Point3f originPoint,Vector3f yAxis ,Vector3f xAxis) {

isUcsSet=true;

ucsCentre.set(point.x,point.y,point.z);

ucsYAxis.set(upvector.x,upvector.y,upvector.z);

ucsXAxis.set(secondAxis.x,secondAxis.y,secondAxis.z);

wcsToUcs.setIdentity();

ucsYAxis.normalize();

ucsXAxis.normalize();

ucsZAxis.cross(ucsXAxis,ucsYAxis);

ucsZAxis.normalize();

ucsToWcs.setColumn(0,ucsXAxis.x,ucsXAxis.y,ucsXAxis.z,0);

ucsToWcs.setColumn(1,ucsYAxis.x,ucsYAxis.y,ucsYAxis.z,0);

ucsToWcs.setColumn(2,ucsZAxis.x,ucsZAxis.y,ucsZAxis.z,0);

ucsToWcs.setColumn(3,ucsCentre.x,ucsCentre.y,ucsCentre.z,1);

wcsToUcs.set(ucsToWcs);

wcsToUcs.invert();

}

public boolean isUcsSet() {

return isUcsSet;

}

public void setUcsSet(boolean isUcsSet) {

this.isUcsSet = isUcsSet;

}

private void reset(){

wcsToUcs.setIdentity();

ucsToWcs.setIdentity();

}

public Matrix4f getUcsToWcs() {

return ucsToWcs;

}

public Matrix4f getWcsToUcs() {

return wcsToUcs;

}

}

————————————————————————————————

Its a basic UCS class and we can incorporate more functionality like rotation and Translation

of UCS.

“>Link