This project has moved. For the latest updates, please go here.

A small query

May 5, 2013 at 3:16 AM
Hi,

Does this library supports OCS to WCS conversion too?
Coordinator
May 6, 2013 at 12:32 AM
Edited May 6, 2013 at 3:16 AM
You can transform any Vector3 from OCS to WCS and viceversa, if that is what you need. Check the methods:
public static Vector3 Transform(Vector3 point, Vector3 zAxis, CoordinateSystem from, CoordinateSystem to)
and
public static List<Vector3> Transform(List<Vector3> points, Vector3 zAxis, CoordinateSystem from, CoordinateSystem to)
in the MathHelper class. They use the implementation of the arbitrary axis algorithm as defined in the dxf documentation. You can also check the method:
public static Matrix3 ArbitraryAxis(Vector3 zAxis)
Daniel
May 6, 2013 at 11:03 AM
Hi Daniel

Thanks for your quick reply. Is there any other global variables which need to be set apart from passing the required variables into the function? Because, I did not get the converted result when I tested with a small example. Can u share with a sample code showing how to use this particular function?

Thanks
Coordinator
May 6, 2013 at 4:20 PM
Take a look at this sample code. It creates a light weight polyline which vertexes are defined in OCS and at the end it converts them to WCS coordinates. You do not need to set any global variable to use those methods, just to pass the required information. You can run the code and load the generated dxf into AutoCad, if you compare the values of the coordinates of the converted vertexes (vertexesWCS list), they should be the same if you id the polyline vertexes in AutoCad.
// vertexes of the light weight polyline, they are defined in OCS (Object Coordinate System)
LwPolylineVertex v1 = new LwPolylineVertex(1, -5);
LwPolylineVertex v2 = new LwPolylineVertex(-3, 2);
LwPolylineVertex v3 = new LwPolylineVertex(8, 15);

LwPolyline lwp = new LwPolyline(new List<LwPolylineVertex> {v1, v2, v3});
// the normal will define the plane where the lwpolyline is defined
lwp.Normal = new Vector3(1, 1, 0);
// the entity elevation defines the z vector of the vertexes along the entity normal
lwp.Elevation = 2.5;

DxfDocument dxf = new DxfDocument();
dxf.AddEntity(lwp);
dxf.Save("OCStoWCS.dxf");

// if you want to convert the vertexes of the polyline to WCS (World Coordinate System), you can
Vector3 v1OCS = new Vector3(v1.Location.X, v1.Location.Y, lwp.Elevation);
Vector3 v2OCS = new Vector3(v2.Location.X, v2.Location.Y, lwp.Elevation);
Vector3 v3OCS = new Vector3(v3.Location.X, v3.Location.Y, lwp.Elevation);
List<Vector3> vertexesWCS = MathHelper.Transform(new List<Vector3> { v1OCS, v2OCS, v3OCS }, lwp.Normal, MathHelper.CoordinateSystem.Object, MathHelper.CoordinateSystem.World);
Hope this helps,
Daniel