## Matrix transforms

Chris Smith
12/7/2021 11:28 PM

Hi All,

When I was generating the code for the last question, I had to remind myself how to get the transform to render the extents. I tried a few different ways which seemed like they should have worked but gave very different results so I'm wondering if anyone can point out what I'm missing...

C# Code:
```void Main()
{

var width = 1000;
var height = 1000;

var t1 = GetTransform1(dxf, width, height);
var t2 = GetTransform2(dxf, width, height);
var t3 = GetTransform3(dxf, width, height);

t1.Dump();
t2.Dump();
t3.Dump();
}

public Matrix4D GetTransform1(DxfModel model, int width, int height)
{
var gdiGraphics3D = new GDIGraphics3D(GraphicsConfig.BlackBackgroundCorrectForBackColor);
gdiGraphics3D.CreateDrawables(model);

var bounds = new Bounds3D();
gdiGraphics3D.BoundingBox(bounds, Matrix4D.Identity);

return DxfUtil.GetScaleTransform(
bounds.Corner1,
bounds.Corner2,
bounds.Center,
new Point3D(0d, height, 0d),
new Point3D(width, 0d, 0d),
new Point3D(width / 2, height / 2, 0d)
);
}

public Matrix4D GetTransform2(DxfModel model, int width, int height)
{
return model.ZoomExtents().GetTransform(new Size2D(width, height), invertYAxis: true);
}

public Matrix4D GetTransform3(DxfModel model, int width, int height)
{
return model.ZoomExtents().GetMappingTransform(new Rectangle2D(0,0,width, height), true);
}```

The first one gives the "correct" answer, the others give different answers ðŸ™‚

Cheers,
Chris

Chris Smith
12/7/2021 11:41 PM

BTW, code assumes you're running in Linqpad to use the Dump() method

Wout
12/7/2021 11:43 PM

Not sure, don't remember the differences between the VPORT transform methods, but I'd just stick with your first method because it's the simplest.

- Wout