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.
Solved! Go to Solution.
Solved by chiefbraincloud. Go to Solution.
try this:
cs.Xaxis.AngleOnPlane(NewPlane(Point3d.Origin, Vector3d.XAxis))
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.
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.