2

enter image description here

I am calculating lines (2 sets of coordinates ) ( the purple and green-blue lines ) that are n perpendicular distance from an original line. (original line is pink ) ( distance is the green arrow )

How do I get the coordinates of the four new points?

I have the coordinates of the 2 original points and their angles. ( pink line )

I need it to work if the lines are vertical, or any other orientation.

Right now I am trying to calculate it by: 1. get new point n distance perpendicular to the two old points 2. find where the circle intersects the new line I have defined.

I feel like there is an easier way.

1
  • Is this a programming or a math question? Aug 18, 2016 at 2:12

2 Answers 2

1

Similarly to @MBo's answer, let's assume that the center is (0,0) and that your initial two points are:

P0 = (x0, y0) and P1 = (x1, y1)

A point on the line P0P1 has the form:

(x, y) = c(x1 - x0, y1 - y0) + (x0, y0)

for some constant c.

Let (u, v) be the normal to the line P0P1:

(u, v) = (y1 - y0, x1 - x0) / sqrt((x1 - x0)^2 + (y1 - y0)^2)

A point on any of the lines parallel to P0P1 has the form:

(x, y) = c(x1 - x0, y1 - y0) + (x0, y0) +/- (u, v)* n         {eq 1}

where n is the perpendicular distance between lines and c is a constant.

What remains here is to find the values of c such that (x,y) is on the circle. But these can be calculated by solving the following two quadratic equations:

(c(x1 - x0) + x0 +/- u*n)^2 + (c(y1 - y0) + y0 +/- v*n)^2 = r^2

where r is the radius. Note that these equations can be written as:

c^2(x1 - x0)^2 + 2c(x1 - x0)*(x0 +/- u*n) + (x0 +/- u*n)^2
 + c^2(y1 - y0)^2 + 2c(y1 - y0)*(y0 +/- v*n) + (y0 +/- v*n)^2 = r^2

or

A*c^2 + B*c + D = 0

where

A = (x1 - x0)^2 + (y1 - y0)^2
B = 2(x1 - x0)*(x0 +/- u*n) + 2(y1 - y0)*(y0 +/- v*n)
D = (x0 +/- u*n)^2 + (y0 +/- v*n)^2 - r^2

which are actually two quadratic equations one for each selection of the +/- signs. The 4 solutions of these two equations will give you the four values of c from which you will get the four points using {eq 1}


UPDATE

Here are the two quadratic equations (I've reused the letters A, B and C but they are different in each case):

A*c^2 + B*c + D = 0                                           {eq 2}

where

A = (x1 - x0)^2 + (y1 - y0)^2
B = 2(x1 - x0)*(x0 + u*n) + 2(y1 - y0)*(y0 + v*n)
D = (x0 + u*n)^2 + (y0 + v*n)^2 - r^2

A*c^2 + B*c + D = 0                                           {eq 3}

where

A = (x1 - x0)^2 + (y1 - y0)^2
B = 2(x1 - x0)*(x0 - u*n) + 2(y1 - y0)*(y0 - v*n)
D = (x0 - u*n)^2 + (y0 - v*n)^2 - r^2
9
  • thanks for your thorough answer. In terms of the formatting of your answer: is (x,y) mean that every x value corresponds to the 1st thing before the comma? Also, is there a difference between c and C in your equations? Also, what is the code equivalent to deal with +/- ? is it a conditional to check n >= 0 ?
    – awongh
    Aug 16, 2016 at 13:02
  • Also, what is D in your 2nd to last equation?
    – awongh
    Aug 16, 2016 at 14:14
  • Please note that I've modified the very last line so that now it defines D, the independent term in the quadratic equation A*c^2 + B*c + D = 0. Aug 16, 2016 at 16:15
  • Yes, the the notation (x,y) means that everything before the comma corresponds to x and everything after the comma to y. This is the standard notation of ordered pairs. Aug 16, 2016 at 16:16
  • thanks!^^ Also, how does the quadratic equation produce 4 values? I assume that it has to do with the arrangement of the +/- signs?
    – awongh
    Aug 16, 2016 at 16:48
0

Let's circle radius is R, circle center is (0,0) (if not, shift all coordinates to simplify math), first chord end is P0=(x0, y0), second chord end is P1=(x1,y1), unknown new chord end is P=(x,y). Chord length L is

L = Sqrt((x1-x0)^2 + (y1-y0)^2)

Chord ends lie on the circle, so

x^2 + y^2 = R^2   {1}

Doubled area of triangle PP0P1 might be expressed as product of the base and height and through absolute value of cross product of two edge vectors, so

+/- L * n = (x-x0)*(y-y1)-(x-x1)*(y-y0) =   {2}
        x*y - x*y1 - x0*y + x0*y1 - x*y + x*y0 + x1*y - x1*y0 = 
        x * (y0-y1) + y * (x1-x0) + (x0*y1-x1*y0)

Solve system of equation {1} and {2}, find coordinates of new chord ends. (Up to 4 points - two for +L*n case, two for -L*n case)

I cannot claim though that this method is simpler - {2} is essentially an equation of parallel line, and substitution in {1} is intersection with circle.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.