javascript - How to find a Parallel line for given A,B coordinates in 2D - Stack Overflow

I have A(x1,y1) and B(x2,y2) coordinates.I have the length and angle of the line.I need to find the par

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
 |  Show 8 more ments

1 Answer 1

Reset to default 10

Your 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)

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744700408a4588744.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信