最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

如何测量对角线距离点?

SEO心得admin135浏览0评论
本文介绍了如何测量对角线距离点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我可以计算水平和垂直点,但无法弄清楚如何使用对角线点计算距离.有人可以帮我吗?

I can compute horizontal and vertical points, but I cant figure out how to compute distance using diagonal points. Can someone help me with this.

这是我的水平和垂直测量的代码:

here's the code for my horizontal and vertical measuring:

private float ComputeDistance(float point1, float point2) { float sol1 = point1 - point2; float sol2 = (float)Math.Abs(Math.Sqrt(sol1 * sol1)); return sol2; } protected override void OnMouseMove(MouseEventArgs e) { _endPoint.X = e.X; _endPoint.Y = e.Y; if (ComputeDistance(_startPoint.X, _endPoint.X) <= 10) { str = ComputeDistance(_startPoint.Y, _endPoint.Y).ToString(); } else { if (ComputeDistance(_startPoint.Y, _endPoint.Y) <= 10) { str = ComputeDistance(_startPoint.X, _endPoint.X).ToString(); } } }

假定已设置_startPoint.

Assuming that the _startPoint has been already set.

在此图像中,对角点显然是错误的.

In this image the diagonal point is obviously wrong.

推荐答案

您需要使用毕达哥拉斯定理.

You need to use Pythagoras' theorem.

d = Math.Sqrt(Math.Pow(end.x - start.x, 2) + Math.Pow(end.y - start.y, 2))
发布评论

评论列表(0)

  1. 暂无评论