Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Geometry - Right Triangles

Status
Not open for further replies.

Glenn9999

Programmer
Jun 19, 2004
2,311
US
This isn't so much a programming problem (well most I see aren't), but it's a problem I'm trying to work out for a program and I'm not sure of it (probably just don't remember fully how to do it in a true logical way.

The problem (draw it out to imagine if you must): Say I have two points on a cartesian coordinate system. Having this information gives us some relative distances, which allows us to form a right triangle. I can take the x and y values and apply the Pythagorean Theorem to get the distance between the two points. All is fine here.

Now I want to draw a point that is between the two original points, where the distance on the x-axis is 1/2 the original distance of the points (basically in the middle), and the y distance is on the hypotenuse of the triangle described in the previous paragraph.

Basically:
Let a be the horizontal x-axis distance between the two points.
Let b be the vertical y-axis distance between the original two points.
let c be the hypotenuse or the actual distance between the two original points.


My initial assumption was that the x-distance for the old point and the new point in between is 0.5a. Therefore, since a new right triangle is formed within the bigger right triangle, the other distances of it would be 0.5b and 0.5c, but I wasn't sure since I'm not sure there's a provable arithmetic relationship as described.

Am I on the right track or is there something I'm missing to solve this problem?
 
Code:
if 
 point a is (x1, y1)
 point b is (x2, y2)
then
 distance ab = sqrt(sqr(x1-x2)+sqr(y1-y2))
 point c (halfway between a and c) is ((x1+x2)/2, (y1+y2)/2)

You don't need half the distances between the x coordinates and y-coordinates, but half the sum of the respective coordinates (or mean values of x- and y- coordinates)

Code:
example:

   Y
   ^
   |
  4+  o a
   |   \
   |    \
   |     \ 8
---+--+---\+----+--->X
 -1+  3    o c  13
   |        \
   |         \
   |          \
   |           \
 -6+            o b
   |

 a = (3, 4)
 b = (13, -6)
ab = sqrt(sqr(13-3)+sqr(-6-4))
   = sqrt(200)
   = 14.142 (approx)

 c = ((3+13)/2), (4 + (-6))/2)
   = (8, -1)

p5
 
Assuming that it's not a vertical line, the approach that I would take is to first determine the equation of the line that contains the two original points. The substitute the known value of x and solve for y.

Y[sub]2[/sub] - Y[sub]1[/sub]
Y - Y[sub]1[/sub] = ( --------- ) (X - X[sub]1[/sub])
X[sub]2[/sub] - X[sub]1[/sub]


Since you know that the target X is halfway along the X axis, it's value can be represented at (X[sub]1[/sub] + X[sub]2[/sub]) / 2, plug that in and solve for Y.

Y[sub]2[/sub] - Y[sub]1[/sub] X[sub]2[/sub] + X[sub]1[/sub]
Y - Y[sub]1[/sub] = ( --------- ) (---------- - X[sub]1[/sub])
X[sub]2[/sub] - X[sub]1[/sub] 2


--------------
Good Luck
To get the most from your Tek-Tips experience, please read
FAQ181-2886
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top