画一条线或圆... [英] Draw a line or circle...

查看:109
本文介绍了画一条线或圆...的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

可能有什么帮助我...

我想编写一个程序,让我用鼠标画一条线或任何形状.然后给我几英寸或几英寸.不是这个,但是我需要它来测量任何形状的长度,就好像它是一条线一样.为了说明,我需要测量从一个特定点到另一点的圆的长度.

非常感谢,

Hi all,

May any help me with this...

I want to write a program to let me draw a line or any shape, with the mouse, for example. Then gives me how long is it with inches or whatsoever. Not this, but I need it to measure any shape''s length as though it is a line. To illustrate,I need to measure the length of the circle from one specific point to another one.

Thanks a lot,

推荐答案

我从您的看法中假设,这基本上是如何获得用鼠标单击的两点之间的线的长度?" -因为您暗示您已经可以绘制形状.
如果是这样,那真的非常简单:只需使用毕达哥拉斯!
I assume from what you say that this is basically "how do I get the length of a line between two points that I click with the mouse?" - since you imply that you can already draw the shapes.
If so, then it is really, really easy: just use Pythagoras!
Point startPoint = new Point(0, 0);
bool down = false;
private void panel1_MouseDown(object sender, MouseEventArgs e)
    {
    startPoint = e.Location;
    down = true;
    }

private void panel1_MouseMove(object sender, MouseEventArgs e)
    {
    if (down)
        {
        Point endPoint = e.Location;
        double length = Math.Sqrt(Math.Pow(endPoint.X - startPoint.X, 2) + Math.Pow(endPoint.Y - startPoint.Y, 2));
        label1.Text = length.ToString();
        }
    }

private void panel1_MouseUp(object sender, MouseEventArgs e)
    {
    down = false;
    }


由于屏幕以像素为单位,尽管您可以以dpi为单位检索屏幕分辨率,但这并不是很精确.因为很难让程序像人眼所见那样能够测量弧度等,所以您必须定义图元,并让用户在扫描的图像上绘制/拟合这些图元.然后,通过绘制图元的几何特性,您还可以进行多次测量/计算.为此,您实际上需要编写一个类似CorelDraw或InkScape的程序(稍微简单一些).尽管您在.net中具有2d矢量图形支持,但是创建这样的程序并非易事.您可以从此处开始:简单矢量形状 [
As the screen is measured in pixels, although you can retrieve the screen resolution in dpi, it is not really precise. As it is really hard to make a program see, as a human sees, to be able to measure arcs and so on, you have to define primitives, and let the user draw/fit those primitives over the scanned image. Than, by having the geometrical properties of primitive drawn, you can also give several measurements/calculations. For that, you actually need to write a program like CorelDraw or InkScape (a little bit simpler). Although you have 2d vector graphics support in .net, creating such a program is not an easy task. You could start here: Simple Vector Shapes[^]


这篇关于画一条线或圆...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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