Rotate to minimum rectangle

Discuss and ask questions about CAD .NET library.

Moderators: SDS, support, admin

Post Reply
shantisoftware
Posts: 6
Joined: 15 Jul 2015, 14:03

Rotate to minimum rectangle

Post by shantisoftware » 08 Jul 2022, 07:13

Has anyone got an algorithm to rotate a CadImage to minimum rectangle.
I have a simple one that is working for most drawings, where I just use CadImage.Rotate about z axis, and iterate through 360 degrees to find the angle with the smallest rectangle via PureExtents.
I came across some examples where the results of cadImage.PureExtents give weird results as I rotate. I can't see why.

support
Posts: 3254
Joined: 30 Mar 2005, 11:36
Contact:

Re: Rotate to minimum rectangle

Post by support » 08 Jul 2022, 10:34

shantisoftware wrote:
08 Jul 2022, 07:13
Has anyone got an algorithm to rotate a CadImage to minimum rectangle.
I have a simple one that is working for most drawings, where I just use CadImage.Rotate about z axis, and iterate through 360 degrees to find the angle with the smallest rectangle via PureExtents.
I came across some examples where the results of cadImage.PureExtents give weird results as I rotate. I can't see why.
Hi,
We have a Viewer demo, that illustrates how the Rotate function works. Most likely, you should recalculate the extents after you rotate the CADImage:

Code: Select all

this.cadImage.Rotate(Axes.Z, angle);
            this.cadImage.GetExtents();
Also, if you want to get pure extents without margins, you should check the IsWithoutMargins property of CADImage.

Catherine.
Technical Support E-mail: support@cadsofttools.com
Chat support on Skype: cadsofttools.support

shantisoftware
Posts: 6
Joined: 15 Jul 2015, 14:03

Re: Rotate to minimum rectangle

Post by shantisoftware » 01 Feb 2023, 10:45

Hi Catherine

From what I can see that method doesn't actually rotate the co-ordinates of the points, as when I load the saved file into another CAD program nothing has changed.

I've used the other sample with RotatePolyLine, RotateText, etc, to work through each entity and rotate it about a common centre point.

Am I missing something?

support
Posts: 3254
Joined: 30 Mar 2005, 11:36
Contact:

Re: Rotate to minimum rectangle

Post by support » 03 Feb 2023, 12:05

shantisoftware wrote:
01 Feb 2023, 10:45
Hi Catherine

From what I can see that method doesn't actually rotate the co-ordinates of the points, as when I load the saved file into another CAD program nothing has changed.

I've used the other sample with RotatePolyLine, RotateText, etc, to work through each entity and rotate it about a common centre point.

Am I missing something?
Hi,
well, the cadImage.Rotate function should be working correctly.
Here is a code example of the Rotate function usage:

Code: Select all

string pathdxffile = @"d://Test.dxf";
   string pathoutdxffile = @"d://Test30.dxf";
   this.cadImage = CADImage.CreateImageByExtension(pathdxffile);
   cadImage.LoadFromFile(pathdxffile);
   cadImage.Rotate(Axes.Z, 30);
   var vExp = new CADImport.Export.DirectCADtoDXF.CADtoDXF(cadImage);
   vExp.Version = DWGVersion.ACR2004;//or choose ACR2000
   vExp.SaveToFile(pathoutdxffile);
If something goes wrong, please, send us your code snippet and file example.
Catherine.
Technical Support E-mail: support@cadsofttools.com
Chat support on Skype: cadsofttools.support

Post Reply