开发者

how to draw parallelogram with 2 points and slope

I have a start point(x0,y0), a end point(x2,y2) and a slope (of line between (x0,y0) and (x3,y3)) and i want to draw开发者_如何学Go a parallelogram.

(x0,y0)       (x1,y1)
     __________
     \         \  
      \         \
       \_________\ 
    (x3,y3)      (x2,y2)

Can somebody tell me how to do this? or suggest some algorithm or something.

Edit: Here y0 = y1 and y2 = y3

Regards


If we denote the slope as m and suppose that y0=y1 and y3=y2, then we can compute x3 like so:

m = (y3 - y0) / (x3 - x0)
y3 = y2
m = (y2 - y0) / (x3 - x0)
m*x3 - m*x0 = y2 - y0
m*x3 = y2 - y0 + m*x0
x3 = (y2 - y0 + m*x0) / m

And similarly:

m = (y2 - y1) / (x2 - x1)
y1 = y0
m = (y2 - y0) / (x2 - x1)
m*x2 - m*x1 = y2 - y0
-m*x1 = y2 - y0 - m*x2
x1 = -(y2 - y0 - m*x2) / m


You do not have enough data. With just two points and a slope you have an infinity of possible parallelograms (two points and a slope defines just two parallels, not a parallelogram).

From your drawing you seem to be looking for the parallelogram with horizontal borders, if so it gives you a second slope and you have y0 = y1 and y2 = y3.

You get x3 using the slop with:

x3 = ((y3-y0)/slope) + x0

There is only x1 still unknown:

x1 = x0 + (x2-x3)

Obviously I did not checked for all degenerating cases when you have no solution or infinite solutions. I leave that to someone else.


In general, if the sides of the parallelogram are not parallel to the axes:

how to draw parallelogram with 2 points and slope

The formulas for z0 and z1 are:

z0 = {  Cos[phi]^2 (X2 + (Y0 - Y2) Cot[theta]) + 
        Cos[phi] (Y0 - Y2 + (X0 - X2) Cot[theta]) Sin[phi] + X0 Sin[phi]^2, 

        Y0 Cos[phi]^2 + 
        Cos[phi] (X0 - X2 + (-Y0 + Y2) Cot[theta]) Sin[phi] + 
        (Y2 + (-X0 + X2) Cot[theta]) Sin[phi]^2
     }

z1 = {  Csc[theta] (Cos[phi - theta] ((-Y0 + Y2) Cos[phi] + X2 Sin[phi]) - 
        X0 Cos[phi] Sin[phi - theta]), 

        Y2 Cos[phi]^2 + 
        Cos[phi] (-X0 + X2 + (Y0 - Y2) Cot[theta]) Sin[phi] + 
        (Y0 + (X0 - X2) Cot[theta]) Sin[phi]^2
     }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜