how to get a boundingbox for multiple items in wpf?

南笙酒味 提交于 2019-12-13 13:18:39

问题


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 ?


回答1:


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.




回答2:


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.




回答3:


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.



来源:https://stackoverflow.com/questions/6115710/how-to-get-a-boundingbox-for-multiple-items-in-wpf

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!