Question

Given the following coordinate points:

trapezoid

Write an algorithm (in pseudocode) to solve for x1, x2, x3, and x4.

This is what I have so far:

 var y1, y2, y3, y4 = 50, 50, 75, 75;

 var offset1 = tan(60) * y1;

 var offset2 = tan(60) * (y2 - y1);

 var x1 = 200 + offset1;

 var x3 = 200 + offset1 + offset2;
Was it helpful?

Solution

Consider the right triangle { (200,0) (350,300) (350,0) } (see the illustration below).

Since the big and the small triangles sharing the (Xb, Yb) corner are similar, the ratio of the length of the red side (X,Y)-(Xb,Y) to the length of (Xb,Y)-(Xb,Yb) is the same as the ratio of (Xa,Ya)-(Xb,Ya) to (Xb,Ya)-(Xb,Yb).

Illustration

Since (X,Y)-(Xb,Y) is your only unknown, you could figure out the answer by solving the equation

Xb-X   Xb-Xa
---- = -----
Yb-Y   Yb-Ya

Therefore,

         (Xb-Xa)*(Yb-Y)
X = Xb - --------------
              Yb-Ya

OTHER TIPS

You know the equations of all the three lines (sides) of the triangle. (You can derive it by the vertex points)

Just plug in the values of y and get the x coordinates.

EDIT: If you know two points on a line (x1,y1) and (x2,y2), then the equation of the line is:

y2-y1   y - y1
----- = ------
x2-x1   x - x1
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top