January 10, 2007

3D Geometric Util Classes

Filed under: 3D Maths — khangharoth @ 1:29 pm

As i am writing Brep Datastructure and operations on them , i had to come up with some basic 3D maths util classes,

like rotation of a Vector about a given Axis .

Also basic classes for primitves say Line : From which i can compute distance , intersection pt etc.

I am using VecMath Libs : Its a Open-Source 3D Math util library resulted as sub-project in Java3D devlopent .

Can be downloaded from this link vecmath.

As of now i am uploading three java files.





Baisc Co-ordinate

Filed under: 3D Maths — khangharoth @ 1:11 pm

Today while implementing Breps in my dataStructure i got a interesting problem to solve .

Basically needed to figure out the distance of a Line -Segment from a specified point so that i can see which is the closet edge in a Object.

Its a Line Segemnt and not whole Line from which we need to find distance . So perpendicular distance is not the smallest distance if the perpendicular does not fall on that segment .So how to solve this.

Well the solution i was able to came up is :

1 ) Make a Plane from two points of LineSegment and specified Pt given .

2) On this plane make two Lines Passing through the end Points of the Segemnt and Perpendicular to it.

3) Now say D is the distance between two end Points of the Segment.

And D1 =Distance of Specified Pt from first Perpendicular.

D2=Distance of Specified Pt from second Perpendicular.

4) If D is greater than D1 and D2 . Than minimum distance of that Specified pt will be Perpendicluar from this point on

the Line Equation.

5 ) Otherwise shorter of the distance between Specified pt and two pts of the Segment is the minimum distance.

Not Bad huh!

November 25, 2006

Making an User Cordinate System : UCS

Filed under: 3D Maths — khangharoth @ 1:07 am

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 ) {
return ucsPoint;


*Give Point in WCS corresoponding to
* UCS Point
* @param node
* @param canvas

public Point3f getWcsCordinates(Point3f ucsPoint ) {
return ucsPoint;


* @param originPoint
* @param yAxis
* @param xAxis
public UcsCoordinates(Point3f originPoint,Vector3f yAxis ,Vector3f xAxis) {

public boolean isUcsSet() {
return isUcsSet;
public void setUcsSet(boolean isUcsSet) {
this.isUcsSet = isUcsSet;
private void reset(){
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.


Create a free website or blog at