
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With