# Finding the component of a vector tangent to a circle

## Problem

Given a vector and a circle in a plane, I'm trying to find the component of the vector that is tangent to the circle. The location of the tangent vector is unimportant; I only need to know its magnitude and whether it is directed clockwise or counter clockwise about the circle.

## Background (just in case you're interested)

I'm writing an iPhone app that displays a dial. The user is allowed to spin the dial by dragging it around with his finger. If the user then flicks his finger in some direction (and lets go), the dial should continue to spin before coming to a stop. For added realism, the amount of spin should be directly proportional to the velocity of the flick. In other words, I'm simulating the inertia and momentum of the dial.

The OS already provides a vector describing the velocity and direction of the flick. Note that if it happened to be tangential to the dial, I could simply find the magnitude of the vector and use it directly as the amount of spin. But the flick could be in any direction -- even outside the dial. A flick along the radius of the dial, for example, should result in no motion. Therefore, I need to find:

1. The component of the flick vector that is tangential to the dial
2. Whether this tangent vector is clockwise or counter clockwise around the dial

With this information, I can calculate how much spin should be put on the dial by finding the magnitude of the tangent vector.

## Illustration

That might not be clear, so here's a diagram to illustrate:

• $V$: flick vector
• $P$: start point of the vector
• $D$: midpoint of the vector
• $T$: tangent vector I'm trying to find
• $E$: point where the tangent vector touches the circle
• $R$: radius of the circle
• $C$: center of the circle
• $T'$: another way of looking at the tangent vector (for an alternate approach described later)
• $V_{2}$, $V_{3}$: other possible flick vectors

## My approach

My first approach was to derive an equation for the tangent line ($T$).

The midpoint $D$ would be given by:

$D = ( P_{x} + \frac{V_{x}}{2}, P_{y} + \frac{V_{y}}{2})$

The slope $m$ of line $\overline{C D}$ would be:

$m = \frac{D_{y} - C_{y}}{D_{x} - C_{x}} = \frac{P_{y}+\frac{V_{y}}{2} - C_{y}}{P_{x} + \frac{V_{x}}{2} - C_{x}}$

And then the equation for line $\overline{C D}$ would be:

$y - C_{y} = m(x - C_{x})$

$E$ would be the intersection of that line and the circle:

$(x - C_{x})^{2} + (y - C_{y})^{2} = R^{2}$

By solving for $x$ and $y$ in the $\overline{C D}$ equation and substituting into the circle equation, I get:

$x = C_{x} ± \frac{R}{\sqrt{1 + m^{2}}}$

$y = C_{y} ± \frac{R}{\sqrt{1 + m^{2}}}$

These $x, y$ values are the coordinates of point $E$.

Now I finally have an equation for the tangent line $T$. I simply use the perpendicular slope of line $\overline{C D}$ and the coordinates of point $E$:

$y - E_{y} = - \frac{1}{m}(x - E_{x})$

I've verified that my work is correct by plugging in some numbers, but I'm not sure what to do next. I still don't have the magnitude of the tangent vector.

## Alternate approach

As an alternate approach, I thought of ignoring $T$ altogether and considering $T'$ instead, since I only need to know the magnitude of the tangent vector. But in the right triangle I only know the length of the hypotenuse ($|V|$). That's not enough information to determine the length of $T'$.

Or, if I could somehow determine the $x, y$ components of $T'$, then I believe the dot product ($V \cdot T'$) would give me the magnitude of the tangential component of the vector V. (Please correct me if I'm wrong.) But I'm not sure how to get those values in the first place.

How can I proceed? Thanks for any suggestions.

-

## 2 Answers

The vector $T$ is the component of $V$ perpendicular to $CD$. Assuming the center of the circle $C$ is the origin, this is just $$T = V - \frac{D(D\cdot V)}{\lVert D\rVert^2}.$$

If you want the signed magnitude of the vector, with positive being anticlockwise and negative being clockwise, you should take the cross product of $D/\lVert D\rVert$ and $V$ instead. In two dimensions, the cross product of two vectors is a scalar, $$u \times v = \begin{vmatrix}u_x & v_x \\ u_y & v_y\end{vmatrix} = u_xv_y - u_yv_x.$$

If the circle is not centered at the origin, just replace $D$ with $D - C$ in all of the above expressions.

-

Thanks for your answer! When you say $D$, I assume you mean the vector from C to D. I applied your formula for $T$ and I seem to be getting the correct values back. However, I'm not understanding your technique for getting the circular direction. I thought the cross product is always a vector, not a scalar. In any case, I applied your function and got a negative value for V (clockwise -- correct) but also a negative value for $V_{2}$ (clockwise -- incorrect). Any thoughts? Thanks. – vocaro Mar 5 '12 at 6:19
Strictly speaking, the cross product is a function from pairs of 3D vectors to 3D vectors, but if you have two 2D vectors $\vec u$ and $\vec v$, the cross product of $(u_x, u_y, 0)$ and $(v_x, v_y, 0)$ is the vector $(0, 0, w)$ where $w = u_xv_y - u_yv_x$, so one can think of $w$ as "the cross product in 2D" of $\vec u$ and $\vec v$. I don't know if it has a more specific name, but it is a fairly natural thing to do. From the picture, I don't think the value for $\vec V_2$ should be negative. Can you tell me the coordinates of $\overrightarrow{CD}$ and $V$ in that case? – Rahul Narain Mar 5 '12 at 17:04
Sorry, my calculations were wrong. $V_{2}$ is indeed positive as you predicted. I have accepted your answer; thank you for your help! – vocaro Mar 6 '12 at 5:25

I think that the simplest way would be like this:

Firstly, find the angle between (the line from the center of the circle to the midpoint of the Vector) and (the Vector itself). (Do you know how to do this? If not, comment and we can expand). I'm capitalizing the V in the Vector we start with to distinguish it.

Once you have this angle $\theta$, then the length of the tangent you're looking for is given by $L\sin^{} \theta$, where $L$ is the length of the Vector. And whether it's clockwise or counterclockwise should come from your calculation of the angle.

Or we could do everything with complex numbers. If the angle that the midpoint-line makes with the positive real axis is $\theta$, then multiply the complex representatives of the endpoints of the Vector by $e^{-i\theta}$, and calculate the imaginary part of the difference $d$ between the endpoints. Then positive and negative correspond to positive and negative imaginary part, respectively. And for that matter, the tangent vector is given by $e^{i \theta} \text{Im}(d)$, where Im stands for the imaginary part.

If you know some complex, then you'll see we rotated the vector so that our tangent point on the circle is always $(1,0)$, so we took the $y$ component and rotated it back.

-

Thanks for your answer! Unfortunately I'm not sure which angle you're calling θ. Do you mean CDP or CPD? I can compute either one using the dot product formula, but after that I'm not sure what to do. For example, I plugged in numbers and got 1.3 radians (75 degrees) for angle CDP, which looks right. But I can't plug this value into your $Lsin^{-1}θ$ formula because the inverse sine only allows values from -1 to 1. By the way, what formula is that? How was it derived? Thanks. – vocaro Mar 4 '12 at 4:09
@Vocaro: Whoops! I didn't mean to include the inverse part of the inverse sine. That was a terrible mistake, and of course you shouldn't get any real value for that part. I just meant to refer to the triangle, that's all. – mixedmath♦ Mar 4 '12 at 6:05
Thanks for the correction. When I apply the dot product formula to find the angle CDP, it looks correct, and when I apply $Lsinθ$, the tangent length looks correct also. However, you said "whether it's clockwise or counterclockwise should come from your calculation of the angle." The dot product formula I'm using is $arccos(\frac{A_{x}B_{x}+A_{y}B_{y}}{|A||B|})$, which will always give a positive angle. Am I using the right formula here? – vocaro Mar 4 '12 at 20:03
{"extraction_info": {"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 74, "mathjax_display_tex": 2, "mathjax_asciimath": 0, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0}, "config": {"markdown_headings": true, "markdown_code": false, "boilerplate_config": {"ratio_threshold": 0.18, "absolute_threshold": 10, "end_threshold": 15, "enable": true}, "remove_buttons": true, "remove_image_figures": true, "remove_link_clusters": true, "table_config": {"min_rows": 2, "min_cols": 3, "format": "plain"}, "remove_chinese": true, "remove_edit_buttons": true, "extract_latex": true}, "english_confidence": 0.936377227306366, "perplexity_flag": "head"}