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();
}
}
}
Assuming that the _startPoint has been already set.
In this image the diagonal point is obviously wrong.
You can use the hypotenuse formula, e.g., from the Pythagorean theorem calculator, to estimate the diagonal of a rectangle, which can be expressed with the following formula: d² = l² + w² , and now you should know how to find the diagonal of a rectangle explicit formula - just take a square root: d = √(l² + w²) .
This means that you will square the x-axis distance (x2 - x1), and that you will separately square the y-axis distance (y2 - y1). Add the squared values together. This will give you the square of the diagonal, linear distance between your two points.
The diagonal formula is a formula for calculating the number of diagonals in various polygons and their lengths. An n-sided polygon's number of diagonal lines = n(n-3)/2, where n is the number of sides.
You need to use Pythagoras' theorem.
d = Math.Sqrt(Math.Pow(end.x - start.x, 2) + Math.Pow(end.y - start.y, 2))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With