Posts

Showing posts with the label Trigonometry

\arccos(1/2) Arccos(1/2) Products

Answer : Note that tan ⁡ ( x ) = 2 sin ⁡ ( x )    ⟺    sin ⁡ ( x ) cos ⁡ ( x ) = 2 sin ⁡ ( x )    ⟺    sin ⁡ ( x ) = 0 ∨ cos ⁡ ( x ) = 1 2 . \begin{align}\tan(x)=2\sin(x)&\iff\frac{\sin(x)}{\cos(x)}=2\sin(x)\\&\iff\sin(x)=0\vee\cos(x)=\frac12.\end{align} tan ( x ) = 2 sin ( x ) ​ ⟺ cos ( x ) sin ( x ) ​ = 2 sin ( x ) ⟺ sin ( x ) = 0 ∨ cos ( x ) = 2 1 ​ . ​ ​ And cos ⁡ ( x ) = 1 2    ⟺    x = π 3 + 2 n π ∨ x = − π 3 + 2 n π , \cos(x)=\frac12\iff x=\frac\pi3+2n\pi\vee x=-\frac\pi3+2n\pi, cos ( x ) = 2 1 ​ ⟺ x = 3 π ​ + 2 nπ ∨ x = − 3 π ​ + 2 nπ , with n ∈ Z n\in\Bbb Z n ∈ Z . In particular, although arccos ⁡ ( 1 2 ) ( = π 3 ) \arccos\left(\frac12\right)\left(=\frac\pi3\right) arccos ( 2 1 ​ ) ( = 3 π ​ ) is indeed a solution of the equation cos ⁡ ( x ) = 1 2 \cos(x)=\frac12 cos ( x ) = 2 1 ​ , it is not the only one. Let x ∈ [ − π 3 , π 3 ] x\in[-\frac{\pi}{3},\frac{\pi}{3}] x ∈ [ − 3 π ​ , 3 π ​ ] . tan ⁡ ( x ) = 2 sin ⁡ ( x )    ⟺    \tan(x)=2\sin(x) \iff tan ( x ) = 2 ...

Calculating Angles Between Line Segments (Python) With Math.atan2

Image
Answer : The easiest and most logically way to get at this problem is using the dot-product. Try this code (I've commented practically everything): import math def dot(vA, vB): return vA[0]*vB[0]+vA[1]*vB[1] def ang(lineA, lineB): # Get nicer vector form vA = [(lineA[0][0]-lineA[1][0]), (lineA[0][1]-lineA[1][1])] vB = [(lineB[0][0]-lineB[1][0]), (lineB[0][1]-lineB[1][1])] # Get dot prod dot_prod = dot(vA, vB) # Get magnitudes magA = dot(vA, vA)**0.5 magB = dot(vB, vB)**0.5 # Get cosine value cos_ = dot_prod/magA/magB # Get angle in radians and then convert to degrees angle = math.acos(dot_prod/magB/magA) # Basically doing angle <- angle mod 360 ang_deg = math.degrees(angle)%360 if ang_deg-180>=0: # As in if statement return 360 - ang_deg else: return ang_deg Now try your variations of lineA and lineB and all should give the same answer. An alternative solution using the fo...