admin管理员组文章数量:1391943
I have A(x1,y1) and B(x2,y2) coordinates.I have the length and angle of the line.
I need to find the parallel line which gives me C(x3,y3) and D(x4,y4) coordinates at a particular distance.Its a slanted line.
Any pseudo code or math formula could help.
Ex: Given Coordinates A(200,0) B(0,450). Angle of the line is 113.962 . Length of the line 492.4.
Help me find C and D coordinates at distance 50 from A, B coordinates.
Please find image below, its a line with angle.
I have A(x1,y1) and B(x2,y2) coordinates.I have the length and angle of the line.
I need to find the parallel line which gives me C(x3,y3) and D(x4,y4) coordinates at a particular distance.Its a slanted line.
Any pseudo code or math formula could help.
Ex: Given Coordinates A(200,0) B(0,450). Angle of the line is 113.962 . Length of the line 492.4.
Help me find C and D coordinates at distance 50 from A, B coordinates.
Please find image below, its a line with angle.
Share Improve this question edited Nov 6, 2018 at 5:18 user10519853 asked Nov 3, 2018 at 15:37 user10519853user10519853 1551 gold badge1 silver badge10 bronze badges 13- how is the distance measured ? is it along x-axis , y-axis or any other angle? – SomeDude Commented Nov 3, 2018 at 15:46
- Just add 50 to the a.x and b.x. The resulting line will be parallel. – bhspencer Commented Nov 3, 2018 at 16:07
- This is pretty basic geometry. Translate A and B by a vector V to get C and D. The length of V is your distance, and the angle of V is some angle that you haven't specified (along the x-axis is straightforward). – Nelfeal Commented Nov 3, 2018 at 16:09
- Its an angular line. Not a vertical or horizontal line. – user10519853 Commented Nov 3, 2018 at 16:22
- Please find attached image @Nelfeal @ bhspencer @ SomeDude. – user10519853 Commented Nov 3, 2018 at 16:29
1 Answer
Reset to default 10Your line has base point (x1,y1)
and direction vector:
(dx, dy) = (x2-x1, y2-y1)
Normalize this vector dividing ponents by vector length:
len = sqrt((x2-x1)^2 + (y2-y1)^2)
(udx, udy) = (dx / len, dy / len)
perpendicular vector:
(px, py) = (-udy, udx)
(note also reverse vector (udy, -udx) to shift onto another side)
Base point for parallel line at distance dist:
(nx, ny) = (x1 -udy * dist, y1 + udx * dist)
Second point, if you need:
(sx, sy) = (nx + dx, ny + dy)
本文标签: javascriptHow to find a Parallel line for given AB coordinates in 2DStack Overflow
版权声明:本文标题:javascript - How to find a Parallel line for given A,B coordinates in 2D - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744700407a2620530.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论