Rotate items to align with the Y axis?

Rotate items to align with the Y axis?

Anonymous
Not applicable
526 Views
1 Reply
Message 1 of 2

Rotate items to align with the Y axis?

Anonymous
Not applicable

I have a drawing with a group of items as a List<Entity>. One of those items is a reference line and I need to rotate all of these entities so that the reference line is aligned with the Y axis.

 

I'm trying to do something like this:

 

Vector3d rotationVector = referenceLine.StartPoint.GetVectorTo(referenceLine.EndPoint);

double rotationAngle = rotationVector.GetAngleTo(Vector3d.YAxis);

foreach (Entity ent in entities)
{
    ent.TransformBy(Matrix3d.Rotation(rotationAngle, Vector3d.ZAxis, centerPoint));

}

 

But obviously this isn't working. Can someone please help point me in the right direction? I've tried several variations on this basic idea and I can get it working half the time, depending on the starting angle of the reference line, but it's never working for all angles. Not sure what I'm doing wrong here and sometimes AutoCAD is giving me fatal errors that can't be caught in a try/catch block. Thank you.

0 Likes
Accepted solutions (1)
527 Views
1 Reply
Reply (1)
Message 2 of 2

Anonymous
Not applicable
Accepted solution

Edit: Problem solved. I dropped the idea of using GetVectorTo/GetAngleTo and calculated the change in angle manually and it seems to be working now. Thanks anyways!

0 Likes