Co-ordinate geometry.

51 Views Asked by At

I have a straight line with it's start and end point coordinate. And I need to find center of arc with r radius and direction clockwise/ anti-clockwise according to requirement, making the line tangent to the arc(at end point of the line), such that only one center from possible should be picked.

enter image description here

Is it possible?

Program in java script or c# would be more fruitful to me.

1

There are 1 best solutions below

2
On BEST ANSWER

Here are the steps:

  1. The initial coordinates of the line are $(x_1,y_1)$, the end of the line is at $(x_2,y_2)$, where the arc is tangent to the line. The radius of curvature is $R$. You need $(x_3,y_3)$, the center of the arc. You have two unknowns, so you need two equations.

  2. Since $(x_2,y_2)$ is on the arc, it is at distance $R$ from the center. You can write this as $(x_2-x_3)^2+(y_2-y_3)^2=R^2$

  3. The line from $(x_3,y_3)$ to $(x_2,y_2)$ is perpendicular to the line from $(x_2,y_2)$ to $(x_1,y_1)$, so the product of the slopes is $-1$. You can write this as $$\frac{y_2-y_1}{x_2-x_1}=-\frac{x_3-x_2}{y_3-y_2}$$

  4. You square the last equation, and you can put $(y_2-y_3)^2$ into the first equation. You are left with a simple equation for $(x_2-x_3)^2=f(x_1,y_1,x_2,y_2,R)$. This obviously has two solutions, one for clockwise arc, one for counterclockwise arc.

  5. Look up vector product on wikipedia to find out about clockwise/counterclockwise rotations. It will involve choosing one of $x_3=x_2\pm\sqrt{f(x_1,y_1,x_2,y_2,R)}$