I have x1,y1 and x2,y2 which forms a line segment. How can I get another line x3,y3 - x4,y4 which is parallel to the first line as in the picture. I can simply add n to x1 and x2 to get a parallel line but it is not what i wanted. I want the lines to be as parallel in the picture.
相关问题
- Sorting 3 numbers without branching [closed]
- Graphics.DrawImage() - Throws out of memory except
- Why am I getting UnauthorizedAccessException on th
- 求获取指定qq 资料的方法
- How to know full paths to DLL's from .csproj f
What you want to do is to offset the coordinates in the orthogonal direction. If you know vector math, multiply the vector created by the distance between the endpoints of the line by the following matrix:
Say that the first line has the points
(x1,y1)
,(x2,y2)
, withx=x2-x1
,y=y2-y1
.We also have
L = sqrt(x*x+y*y)
, the length of the line (pardon the notation). Then the next line should be offset by=>
dx = -y / L
,dy = x / L
which is the normalized offset for the new line.In C#-like pseudocode:
Did you try subtracting n to y1 and y2 along with adding n to x1 and x2? I guess that may work