What is the formula for finding the angle of the tangent line. ie. I need angle of the line "ab"
Thanks in advance.
I want to find the slope of the line "ab". I know the circle radius, the point(x and y) where the line is touching the circle and also I know the line width. The line can touch any point on the circle and it can be in any direction see the picture.
Assuming the centre of your circle is at the origin (0,0),
then the slope of the radius m_r at point (x,y) is :-
m_r = y/x
The tangent is at right angles to the radius.
For lines at right angles, the product of the slopes is equal to 1.
So the slope of the tangent m_t at point (x,y) times m_r is equal to 1 :-
m_r * m_t = 1
m_t = 1/m_r
m_t = x/y
If you want the angle A of the tangent, just find the inverse tan of the slope :-
A = arctan(m_t)
A = arctan(x/y)
Thanks for your reply. Actually I want to calculate the tangent line starting point(x2,y2) and ending point(x3,y3). I Know the circle radius(r), tangent line width, in the circle where the tangent line intersecting(x1,y1) ,center point of the circle (c) and radius angle. For different radius angle I want to calculate tangent line start and end points. The tangent line center point always touches the circle.
OK Ill have a go
Let your circle center be at (xc,yc)
Radius angle = Ar
Tangent angle = At
then x1 = xc + (r * cos(Ar))
and y1 = yc + (r * sin(Ar))
From these and my post above
At = arctan(x1/y1)
[note - if you are doing this on a computer then use arctan2()
You may also be able to find the angle if you just add 90 deg or pi/2 rad to the radius angle ie
At = Ar + 90
At = Ar + (pi/2) ]
Let delta_x = difference in x values between points 1 & 2, and between points 3 & 1
delta_y = difference in y values
and L = tangent line length
delta_x = cos(At) * L / 2
delta_y = sin(At) * L / 2
Now you can find the start and end points...
x2 = x1 - delta_x
y2 = y1 - delta_y
x3 = x1 + delta_x
y3 = y1 + delta_y
I haven't tested this, so you will have to check it to make sure it works.
Thanks for your reply. But this formula is giving correct result only for the radius angles 0 , 90, 180, 270 and 360 for other angles is not giving correct results. for some angles the points(x2,y2 andx3,y3) are going inside of the circle But the points should be always outside of the circle for all radius angles(see diagram).
I am using the belew code
cicle center point - 200, 200
radius - 150
line length = 200
double x = (200+ (150*Math.cos(90*(Math.PI/180))));
double y = (200+(150*Math.sin(90*(Math.PI/180))));
long tangentAngle = Math.round(Math.atan( (200-x) / (200-y )) * (180 / Math.PI));
double deltaX = Math.cos(tangentAngle * Math.PI / 180) * 200/2;
double deltaY = Math.sin(tangentAngle * Math.PI / 180) * 200/2;
double x2 = x - deltaX;
double y2 = y - deltaY;
double x3 = x + deltaX;
double y3 = y + deltaY;
I can see two potential problems here...
1) Using atan(x/y) to find the Tangent Angle will give odd results as it cant check which quadrant it is operating in in order to give the correct output. This is why I suggested using atan2, which can give correct output over the full 360 deg range, but not all software/calculators support it. Its easier in this case to just add 90 deg or pi/2 rad to the Radius Angle to find the Tangent Angle...
long tangentAngle = RadiusAngle + 90;
2) Its not clear how you are inputting the Radius Angle into your code but you could be having a problem with the fact you are measuring the angle counter-clockwise while you software is expecting it to be clockwise. If so then just subtract the Radius Angle from 360 to obtain the correct Radius Angle...
Radius Angle = 360 - Radius Angle
I was able to get it to work on my system with both these fixes enabled,
hope this helps.