I am looking to find the angles of line features relative to the tangent of a circle. Please see this example for general idea. Angles to line features (purple) I am looking for are (poorly drawn) black hashes, which are relative to the yellow hashed tangents.
I would ultimately like the outcome to be in polar coordinates (0=East, 270=South) and referenced from 0 to 180. The only data I am provided are coordinates to the start/end of my lines (see example link). I have standardized all of my (purple) lines to have a starting $x_0$ coordinate to be the south-most location, giving $\Delta x \geqslant 0$. So my $y$ values will swing in direction, causing $\Delta y$ values to be both positive and negative. This is not the case for the spokes (orange).
I am not a mathematician. To figure this out I have been drawing schematics for each quadrant to determine the relative $\theta$ equations. I was successful for a few test examples in Excel but when applied to all my lines, I found outcomes that were not right. My nested if/and statement is quite long. If anyone would like me to post, I will adjust for clarity.
I have also tried a dot product equation :
$$\arccos\left(\frac{(x_2-x_1, y_2-y_1)\centerdot(y_1-x_1)}{\left[\text{length between}\: (x_0,y_0) \:\text{and} \: (x_1,y_1)\right]\times\left[(\text{length between}\: (x_1,y_1) \:\text{and} \: (x_2,y_2)\right]}\right) $$ I am getting angles between 1 and 2.5.
Is there a tested method or equation that I am unaware of to determine angles relative to the tangent of a circle?
This is an image of my actual lines with spokes radiating from my $(x_0, y_0)$ centerpoint to each bend in my fractures (lines). I have quite a few, hence automation is key...
Much appreciated!
The underlying problem that you’re running into is in the way that your endpoint data are stored: it’s making this somewhat more complicated than it needs to be. If we turn all of those lines in your diagram into vectors, it appears that you’re looking for the angle between a vector that is rotated 90° clockwise from a radial line and a vector that points “away” from the circle. Once you have these two vectors, computing the angle between them is a straightforward calculation that can be done using the dot product, as you’ve mentioned. Unfortunately, because the endpoints are stored with the least $x$-coordinate first, you can’t simply subtract the first point from the second to get the vector that you need for this calculation.
What it comes down to is determining the correct orientation for the vector that represents the target line. Looking closely at the diagram again, we want it oriented so that it’s at an angle $0\lt\theta\lt\pi$ counterclockwise from the “tangent” vector. This is precisely the condition for their cross product to point in the positive $z$ direction (if we view them as 3-D vectors, that is), which suggests the following procedure:
Set $\mathbf v=\langle y_1-y_0,x_0-x_1\rangle$, $\Delta x=x_3-x_2$ and $\Delta y=y_3-y_2$. If you like, you can normalize $\mathbf v$ now by dividing it by its length. Compute $\mathbf{v}_x\Delta x+\mathbf{v}_y\Delta y$ (this is the $z$-component of the cross product) and examine its sign. If it’s zero, the angle is zero and you’re done. If it’s positive, you’ve got the correct orientation, so set $\mathbf w=\langle\Delta x,\Delta y\rangle$; if negative, you need to flip this vector, so set $\mathbf w=-\langle\Delta x,\Delta y\rangle$. A compact way to express this is $$\mathbf w=\operatorname{signum}(\mathbf{v}_x\Delta x+\mathbf{v}_y\Delta y)\,\langle\Delta x,\Delta y\rangle$$ (you can use the
SIGNfunction for this in Excel). Now you can compute the angle between them using $$\cos\theta={\mathbf v\cdot\mathbf w\over\|\mathbf v\|\|\mathbf w\|}$$ and be assured of getting the right one.Since $\|\mathbf a\times\mathbf b\|=\|\mathbf a\|\|\mathbf b\|\sin\theta$, you could also recover the angle from the cross product, but then you’d have to do more checking to figure out which of the possible angles is the correct one.