Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find position of point that is x unit distant from AB line segment and y unit distant from BC line segment?

Representation image

I am trying to calculate coordinates of point P, which is x units distant from AB line segment and y units distant from BC line segment.

Edit: I am trying to write code for general solution. As parameters, I have three points (coordinates) A, B and C and also two values for distance x and y.

like image 316
Tony Avatar asked Jan 28 '26 10:01

Tony


1 Answers

Let's translate all points A,B,C by (-BX, -BY) to set coordinate origin to B, new points are a, 0, c, and I would rename you distances to dc and da.

New coordinates

cy = CY - BY
cx = CX - BX
ay = AY - BY
ax = AX - BX

Then line 0c will have equation

(-cy * x + cx * y) / Sqrt(cx*cx +cy*cy) = 0

line 0a will have equation

(-ay * x + ax * y) / Sqrt(ax*ax +ay*ay) = 0

Let's lc = Sqrt(cx*cx +cy*cy) and la = Sqrt(ax*ax +ay*ay) (lengths of BC and BA segments)

If point p=(px, py) lies at dc distance from line 0c, and at da distance from line 0a, then

Abs(-cy * px + cx * py) = dc * lc
Abs(-ay * px + ax * py) = da * la

If your points always form counterclockwise order of BC, BP, BA rays, you may use this sign combination only and find single solution:

-cy * px + cx * py = dc * lc
-ay * px + ax * py = - da * la

Solve this linear system for px and py, in the end shift coordinates back by BX, BY

PX = px + BX
PY = py + BY

P.S. In extra case angle ABC=180 system has no solution for da<>dc or infinite number of solutions for da=dc

like image 197
MBo Avatar answered Jan 31 '26 00:01

MBo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!