Formula for 2 vectors

78 Views Asked by At

Hello StackExchange people,

I have an issue. I need to create a formula to find degrees and size at a math issue.

So I have $0-359$ degrees and a length of $2$ lines, and I need to get the length and degrees of the third vector (the resulting) with a single formula. I believe (not sure though) $\sin, \cos$ and/or $\tan$ might be required. Am I right?

The reason I'd need just a formula is because this is for programming an applet I'm making and I'm having problems with this part. Having this would make me able to finish my program.

1

There are 1 best solutions below

2
On BEST ANSWER

Represent you vectors by complex numbers. Then your two vectors are $a_1e^{i\theta_1}$ and $a_2e^{i\theta_2}$. But to add them you need to get them into Cartesian form. Use Euler's formula for that: $re^{i\theta} = r(\cos(\theta) + i\sin(\theta))$. Then add up the real parts and imaginary parts. And finally, if you need the angle and length back you can convert them back into polar form via $r= \sqrt{x^2+y^2}$ and $\theta = \operatorname{atan2}(y,x)$, where $x$ is the real part and $y$ is the imaginary part.

Let's take an example. Say your two vectors are $a=2e^{3i}$ (meaning a vector with length $2$ and an angle of $3\ \text{rad}$) and $b=4.2e^{2i}$ (meaning a vector with length $4.2$ and an angle of $2\ \text{rad}$). Then $a=2\cos(3) + 2i\sin(3)$ and $b=4.2\cos(2)+4.2i\sin(2)$.

So $$a+b = (2\cos(3)+4.2\cos(2)) + (2\sin(3)+4.2\sin(2))i$$. Converting that back to polar form we get $r=\sqrt{(2\cos(3)+4.2\cos(2))^2 + (2\sin(3)+4.2\sin(2))^2}\approx 5.54$ and $\theta = \operatorname{atan2}(2\sin(3)+4.2\sin(2), 2\cos(3)+4.2\cos(2)) \approx 2.31\ \text{rad}$. So your final vector is $$a+b = \require{enclose}\enclose{box}{5.54e^{2.31 i}}$$