My app gives the distance between 2 points made on a picturebox. Previously they were doing this by hand and wanted an app to do it. However when you make the line, the distance for that line using the below formula for even a small line for example is 30
However when you use a ruler with 1/32 on it, the measurement is 5/32.
So what is 30? What type of distance is used here and how do I convert this to display the number as it would using a ruler with 1/32 measurement?
//Distance between 2 points.
// ______________________
//d = √ (x2-x1)^2 + (y2-y1)^2
dist = (Convert.ToInt32(Math.Sqrt(Math.Pow(Math.Abs(p2List[i].X - p1List[i].X), 2) + Math.Pow(Math.Abs(p2List[i].Y - p1List[i].Y), 2))));
So here's what I've done.
Vector2 src = new Vector2(p1List[i].X, p1List[i].Y); //first point on the image
Vector2 dst = new Vector2(p2List[i].X, p2List[i].Y); //second point on the image
float Density = 38;
Vector2 dif = dst - src; //difference between the vectors
float len = dif.Length(); //length of the vector, in this case the distance in pixels
float inchLen = len / Density; //density is a float with the image DPI's
DataGridViewRow row = dataGridView1.Rows[rowId];
row.Cells["colLength"].Value = inchLen;
This, for the little line I made, gives me 0.7649706
But I don't know how to make that say a 3,5,6
or whatever it would be if measured using the 1/32 on a ruler.