5
votes

I have several items, i want to calculate a minimum rectangle in which they can be fit, but items are rotated to some degree, or skewed or both. So how do i get the least rectangle which can contain all ?

3

3 Answers

1
votes

You can get the bounding Box for each item, calculate its four extreme points, then apply the transforms on them (skew, rotate, ...)

Then you can easily calculate the bounding box by computing the min and max x and y for all of these points.

1
votes

Here is an link to an implementation of a Dynamic Canvas. This control automatically sizes itself to fit its contents, so the answer to your problem can be found in this code. Look at the MeasureOverride function.

0
votes

Do a foreach on the list of items you want. In each iteration of the loop, get the item's Canvas position (upper left) and add ActualWidth/ActualHeight to get lower right point. Take the upper left and lower right points and call Transform.Transform to get the ACTUAL upper left and lower right points.

Keep track of min and max upper left and lower right to get your bounding box.