在C#中查找多边形的高度和宽度 [英] Finding the Height and width of a Polygon in C#

查看:141
本文介绍了在C#中查找多边形的高度和宽度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我们如何找到由一些点组成的多边形的高度和宽度.

例如:在窗口上,每单击一次鼠标,鼠标单击一次都会给出一个点,如果我单击一个按钮,则鼠标单击的位置将合并并形成一个形状.
直到这很好.我可以计算中心点,但如何找到所形成形状的高度和宽度.

任何人都可以给我一个更好理解的例子

谢谢,

Hi,
How can we find the Height and width of a polygon which is formed with some points.

Eg:on the window each mouse click gives a point after some clicks if i click on a button the mouse click locations will join and form a shape.
Till this it is fine. iam able to calculate the center point, but how we can find the height and width of the formed shape.

any one can give me a example for better understanding

Thanks,

推荐答案

每次通过鼠标单击在屏幕上设置一个点时,您都​​必须注意以下几点.

Everytime you set a point to the screen via a mouse click you''ll have to take note of the following.


  1. X min = int.MaxValue;
    X max = int.MinValue;

    Y min = int.MaxValue;
    Y max = int.MinValue;
  2. 如果当前设置的X坐标小于X min ,请将其设置为X.
    如果当前设置的X坐标大于X max ,则将其设置为X.
    如果当前设置的Y坐标小于Y min ,则将其设置为Y.
    如果当前设置的Y坐标大于Y max ,则将其设置为Y.
  3. 最终按下按钮绘制多边形时,边界矩形由以下坐标定义:

    左上角:(X min ,Y max )
    右上角:( X max ,Y max )
    左下角:(X min ,Y min )
    右下角:( X max ,Y min )
    高度:Y max -Y min
    宽度:  X max -X min


  1. Xmin = int.MaxValue;
    Xmax = int.MinValue;

    Ymin = int.MaxValue;
    Ymax = int.MinValue;
  2. If the currently set X coordinate is smaller than than Xmin, set that to X.
    If the currently set X coordinate is greater than than Xmax, set that to X.
    If the currently set Y coordinate is smaller than than Ymin, set that to Y.
    If the currently set Y coordinate is greater than than Ymax, set that to Y.
  3. When you finally press the button to draw your polygon, the bounding rectangle is defined by these coordinates:

    Upper left corner:  ( Xmin, Ymax )
    Upper right corner: ( Xmax, Ymax )
    Lower left corner:  ( Xmin, Ymin )
    Lower right corner: ( Xmax, Ymin )
    Height: Ymax - Ymin
    Width:  Xmax - Xmin



最好的问候,

—MRB



Best Regards,

—MRB


将所有点添加到System.Drawing.Drawing2D.GraphicsPath,这样便可以调用其BoundingBox属性.它的类型为RectangleF,因此公开了开发人员可能想知道的所有坐标.
Add all your points to a System.Drawing.Drawing2D.GraphicsPath, then you are able to call its BoundingBox property. It is of type RectangleF and therefore exposes all co-ordinates a developer can ever want to know.


这篇关于在C#中查找多边形的高度和宽度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆