.NET

Reply
Member
BR-RRAD
Posts: 3
Registered: ‎06-03-2011
Message 1 of 4 (1,305 Views)
Accepted Solution

Calculating the angle between UCS and WCS

1305 Views, 3 Replies
06-03-2011 04:27 AM

Hi,

 

A "noob" question im afriad regarding converting angles between co-ordinate systems in AutoCAD .NET. Im struggling to find much on the subject and would appriciate some help or a point in the right direction.

 

The Problem:

Im creating my first little utility to form selected block attibute references into a nice neat list. The current version takes a selection of blocks and a list insert location and then moves the attribute references to the location and rotates them to WCS angle of 0.

 

I now want to expand the program to make it a little more flexible and allow you to form the list parrallel to the currently selected UCS x axis (the i.e. and angle of 0 in relation to current ucs's).

 

I have managed bumble my way through and transform the attribute positions correctly to form a list relative to the current UCS but am strugling on how to work out in code what the equivlanent WCS angle value would be.

 

I have done some calcs using .net framework to calculate an angle between two vectors (see code extract below). But this introduces a small error into the angles (i.e. if my ucs is set rotated 45 degrees around the zed and i use the below maths, the resulatant angle is 45.0000002 when read in acad afterwards).

 

Matrix3d ucsCur = ed.CurrentUserCoordinateSystem;

CoordinateSystem3d cs = ucsCur.CoordinateSystem3d;


// the below seems to work by calugulating the angle between two vetrex using .net maths class but this introduce a small accuracy error. Is there a better way?

Double rotAngle = Math.Acos((1 * cs.Xaxis.X) + (0 * cs.Xaxis.Y) + (0 * cs.Xaxis.Z));

 

//set the attribute reference rotation to the calculated WCS radian rotation value "rotAngle" 

attRef.Rotation = rotAngle;

 

Im sure there is a better way built into the managed autocad wrapper using a tranform matix and the ucs vertex information but dont really know how to go about it. Any ideas? Also, if anyone know of any links explaining how to work with the UCS in .net they would be appriciated.

 

Regards,

 

Richard.

 

 

try this:

 

cs.Xaxis.AngleOnPlane(NewPlane(Point3d.Origin, Vector3d.XAxis))

*Expert Elite*
chiefbraincloud
Posts: 753
Registered: ‎02-13-2008
Message 2 of 4 (1,281 Views)

Re: Calculating the angle between UCS and WCS

06-03-2011 11:08 AM in reply to: BR-RRAD

try this:

 

cs.Xaxis.AngleOnPlane(NewPlane(Point3d.Origin, Vector3d.XAxis))

Dave O.                                                                  Sig-Logos32.png
Member
BR-RRAD
Posts: 3
Registered: ‎06-03-2011
Message 3 of 4 (1,260 Views)

Re: Calculating the angle between UCS and WCS

06-04-2011 05:54 AM in reply to: chiefbraincloud

Thanks!

 

That seems to work a treat. I had to make one small change which was to specify "vector3d.zaxis" in the plane constructor parameters rather than "vector3d.xaxis" as shown below:

 

 

Double rotAngle = cs.Xaxis.AngleOnPlane(new Plane(Point3d.Origin, Vector3d.ZAxis));

 

I don't know for sure (thanks to lack of intellisense summary information for the autocad .net classes and not having the AutoCAD.net developer guide to hand atm), but i assume vector3d in the plane contructor is to provide the facing/ normal direction of the plane. So to get a plane in the xy orientation you have to pass a Z vector. 

*Expert Elite*
chiefbraincloud
Posts: 753
Registered: ‎02-13-2008
Message 4 of 4 (1,239 Views)

Re: Calculating the angle between UCS and WCS

06-05-2011 12:53 PM in reply to: BR-RRAD

Sorry, my post should have said ZAxis in the constructor...  Not sure how that happened really, I copied and pasted that from working code.  And that is correct the constructor is looking for the Normal vector.

Dave O.                                                                  Sig-Logos32.png
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Are You Going To Be @ AU 2014? Feel free to drop by our AU topic post and share your plans, plug a class that you're teaching, or simply check out who else from the community might be in attendance. Ohh and don't forgot to stop by the Autodesk Help | Learn | Collaborate booths in the Exhibit Hall and meet our community team if you get a chance!