绘图后得到距离 [英] Get distance mesure after drawing
问题描述
嗨我通过importin数据制作了一个2d自动绘图的应用程序。不是我的积分是绘制,我想计算两点之间的距离并自动显示它和屏幕。
我需要移动它,如果有必要绘制质量视图
我尝试过:
double
dblDistX = Math.Abs(pt1.X - pt2.X);
double
dblDistY = Math.Abs(pt1.Y - pt2.Y);
看起来像一个好的开始;寻找X&的增量Y坐标。double dblDistX = Math.Abs(pt1.X - pt2.X);
double dblDistY = Math.Abs(pt1.Y - pt2.Y);现在我猜你想要的这两点之间的对角线距离(Z)。是时候打破HS几何书了,看看我的朋友毕达哥拉斯,看看他对定理有什么。
Pythagoreas写道:在一个直角三角形:斜边的平方等于另外两边的平方和。
更新02/14/2019
这就是手写数学的方式:
z 2 = x 2 + y 2
z =√(x 2 + y 2 )
我的原始答案包括此代码,该代码没有特定的语言。根据下面的评论,我被告知这适用于VB' VB解决方案
double Z =(dblDistX ^ 2 + dblDistY ^ 2)^。 5
C#是OP使用的,所以这里有2个版本; long long version和1 liner// C#version
// 长版
double dblSqrdDistX = Math.Pow(dblDistX, 2 );
double dblSqrdDistY = Math.Pow(dblDistY, 2 );
double dblSqrdHypotenuseZ = dblSqrdDistX + dblSqrdDistY;
double Z = Math.Sqrt(dblSqrdHypotenuseZ);
// 简短版
double Z = Math.Sqrt(Math.Pow(dblDistX, 2 )+ Math.Pow(dblDistY, 2 跨度>));
Hi iam make an app for 2d automatic drawing by importin data. Not my points are draw, i want to calculate distance between two points and show it automaticaly and the screen.
I would need to move it if necessary for drawing quality view
What I have tried:
double dblDistX = Math.Abs(pt1.X - pt2.X); double dblDistY = Math.Abs(pt1.Y - pt2.Y);
Looks like a good start; finding the deltas for the X & Y coordinates.double dblDistX = Math.Abs(pt1.X - pt2.X); double dblDistY = Math.Abs(pt1.Y - pt2.Y);Now I'm guessing that you want the diagonal distance (Z) between these 2 points. Time to break out the HS Geometry book and look up my buddy Pythagoreas and see what he has for theorems.
Pythagoreas wrote:In a right angled triangle: the square of the hypotenuse is equal to the sum of the squares of the other two sides.
Update 02/14/2019
This is how it would be in handwritten math:
z2 = x2 + y2
z = √(x2 + y2)
My original answer included this code which was in no specific language. From the comments below I was informed that this would work for VB' VB Solution double Z = (dblDistX^2 + dblDistY^2)^.5
C# is what the OP is using so here are 2 versions of it; the long long version and the 1 liner// C# version // long version double dblSqrdDistX = Math.Pow(dblDistX,2); double dblSqrdDistY = Math.Pow(dblDistY,2); double dblSqrdHypotenuseZ = dblSqrdDistX + dblSqrdDistY; double Z = Math.Sqrt(dblSqrdHypotenuseZ); // short version double Z = Math.Sqrt(Math.Pow(dblDistX,2) + Math.Pow(dblDistY,2));
这篇关于绘图后得到距离的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!