Skip to content

Instantly share code, notes, and snippets.

@BriSeven
Last active January 8, 2020 05:17
Show Gist options
  • Save BriSeven/375efe6da59603c6c9866cb469ea90f1 to your computer and use it in GitHub Desktop.
Save BriSeven/375efe6da59603c6c9866cb469ea90f1 to your computer and use it in GitHub Desktop.
Math and tag test #math #circles #latex

math test #tagtest

Right now a20 is this:

$a_{20}=1.6$

representing the angle on the PTT solution circle that solves for the two connection circles. for an optimal curve (where both circle segments are equal in length), I want to find

$0=\left|a_{17}r_1\right|-\left|a_{19}r_2\right|$

where

$a_{17}=4\arcsin\left(\frac{\sqrt{\left(x_{17}-x_3\right)^2+\left(y_{17}-y_3\right)^2}}{2}\right)$

$a_{19}=4\arcsin\left(\frac{\sqrt{\left(x_{19}-x_4\right)^2+\left(y_{19}-y_4\right)^2}}{2}\right)$

and

$r_1=0.5\frac{-x_{13}^2-y_{13}^2}{x_3x_{13}+y_3y_{13}}$

$r_2=0.5\frac{(x_{13}-1)^2+y_{13}^2}{x_4(x_{13}-1)+y_4y_{13}}$

The arcsin business above is a suboptimal way of finding these circle segment lengths. It's really kind of an arctan for two vectors each. One measures the angle in radians between vectors 17 and 3, the other between 19 and 4

so can we simplify those arcsin things? Here's all the variables inside it.

$x_{17}=\frac{-y_{13}}{\sqrt{y_{13}^2+x_{13}^2}}$ $y_{17}=\frac{x_{13}}{\sqrt{y_{13}^2+x_{13}^2}}$ $x_{19}=\frac{y_{13}}{\sqrt{y_{13}^2+\left(-x_{13}+1\right)^2}}$ $y_{19}=\frac{-x_{13}+1}{\sqrt{y_{13}^2+\left(-x_{13}+1\right)^2}}$

$y_3=\frac{y_1}{\sqrt{x_1^2+y_1^2}}$ $x_3=\frac{x_1}{\sqrt{x_1^2+y_1^2}}$ $y_4=\frac{y_2}{\sqrt{x_2^2+y_2^2}}$ $x_4=\frac{x_2}{\sqrt{x_2^2+y_2^2}}$

so these are just normalised vectors. another way to write them is

$v_{17}=||v_{13}||$
$v_{19}=||v_{13}-(1,0)||$
$v_3=||v_1||$
$v_4=||v_2||$

so v17 and v19 represent the vector between the "solution" point v13, and the starting points and end points. v3 and v4 represent the normalised vector angles for each circle edge.

$a_{17}=4\arcsin\left(\frac{1}{2}\sqrt{\left(\frac{-y_{13}}{\sqrt{y_{13}^2+x_{13}^2}}-\frac{x_1}{\sqrt{x_1^2+y_1^2}}\right)^2+\left((\frac{x_{13}}{\sqrt{y_{13}^2+x_{13}^2}})-(\frac{y_1}{\sqrt{x_1^2+y_1^2}})\right)^2}\right)$

$a_{19}=4\arcsin\left(\frac{1}{2}\sqrt{\left(\frac{y_{13}}{\sqrt{y_{13}^2+\left(-x_{13}+1\right)^2}}-\frac{x_2}{\sqrt{x_2^2+y_2^2}}\right)^2+\left(\frac{-x_{13}+1}{\sqrt{y_{13}^2+\left(-x_{13}+1\right)^2}}-\frac{y_2}{\sqrt{x_2^2+y_2^2}}\right)^2}\right)$

okay subbed in and simplified somewhat. let's pull r in.

$q_1=(0.5\frac{-x_{13}^2-y_{13}^2}{x_3x_{13}+y_3y_{13}})*4\arcsin\left(\frac{1}{2}\sqrt{\left(\frac{-y_{13}}{\sqrt{y_{13}^2+x_{13}^2}}-\frac{x_1}{\sqrt{x_1^2+y_1^2}}\right)^2+\left((\frac{x_{13}}{\sqrt{y_{13}^2+x_{13}^2}})-(\frac{y_1}{\sqrt{x_1^2+y_1^2}})\right)^2}\right)$

$q_2=(0.5\frac{(x_{13}-1)^2+y_{13}^2}{x_4(x_{13}-1)+y_4y_{13}})*4\arcsin\left(\frac{1}{2}\sqrt{\left(\frac{y_{13}}{\sqrt{y_{13}^2+\left(-x_{13}+1\right)^2}}-\frac{x_2}{\sqrt{x_2^2+y_2^2}}\right)^2+\left(\frac{-x_{13}+1}{\sqrt{y_{13}^2+\left(-x_{13}+1\right)^2}}-\frac{y_2}{\sqrt{x_2^2+y_2^2}}\right)^2}\right)$

so we're minimizing

$0=\left|q_1\right|-\left|q_2\right|$

let's try and simplify that as much as we can without any drastic measures.

$q_1= 2 \frac{-x_{13}^2-y_{13}^2} {x_3x_{13}+y_3y_{13}} \arcsin\left( \frac{1}{2} \sqrt{ \left( - \frac{y_{13}}{\sqrt{y_{13}^2+x_{13}^2}} - \frac{x_1}{\sqrt{x_1^2+y_1^2}} \right)^2+ \left(\frac{x_{13}}{\sqrt{y_{13}^2+x_{13}^2}} - \frac{y_1}{\sqrt{x_1^2+y_1^2}}\right)^2 } \right)$

$q_2= 2 \frac{(x_{13}-1)^2+y_{13}^2} {x_4(x_{13}-1)+y_4y_{13}} \arcsin\left( \frac{1}{2} \sqrt{\left(\frac{y_{13}}{\sqrt{y_{13}^2+\left(-x_{13}+1\right)^2}}-\frac{x_2}{\sqrt{x_2^2+y_2^2}}\right)^2+\left(\frac{-x_{13}+1}{\sqrt{y_{13}^2+\left(-x_{13}+1\right)^2}}-\frac{y_2}{\sqrt{x_2^2+y_2^2}}\right)^2} \right)$

We know because of their form, many of these are on the unit circle, which means we can convert them to sine and cosine with a shared parameter.

$q_1 = 2 \frac{-x_{13}^2-y_{13}^2} {x_3x_{13}+y_3y_{13}} \arcsin\left( \frac{1}{2} \sqrt{ \left( -\sin{ a_{13} } -\cos{a_1} \right)^2 +\left( \cos{a_{13}} - \sin{a_1} \right)^2 } \right)$

$q_2= 2 \frac{(x_{13}-1)^2+y_{13}^2} {x_4(x_{13}-1)+y_4y_{13}} \arcsin\left( \frac{1}{2} \sqrt{ \left( \frac{y_{13}}{\sqrt{y_{13}^2+\left(-x_{13}+1\right)^2}} -\cos{a_2} \right)^2 +\left( \frac{-x_{13}+1}{\sqrt{y_{13}^2+\left(-x_{13}+1\right)^2}} -\sin{a_2} \right)^2 } \right)$

it's unclear what to do with these terms that have +1 in them. Is that a simple offset?

setting that aside, wolfram alpha says I can simplify the first one a bit further

$q_1 = 2 \frac{-x_{13}^2-y_{13}^2} {x_3x_{13}+y_3y_{13}} \arcsin\left( \frac{1}{\sqrt{2}} \sqrt{ (sin(a_{13} - a_1) + 1) } \right)$

so back to this: We can deal with the other equation by saying

$x_{14}=-x_{13}+1$
$y_{14}=y_{13}$

thus simplifying to $q_2= 2 \frac{x_{14}^2+y_{14}^2} {x_4 x_{14} +y_4y_{14}} \arcsin\left( \frac{1}{2} \sqrt{ \left( \frac{y_{14}}{\sqrt{y_{14}^2+x_{14}^2}} -\cos{a_2} \right)^2 +\left( \frac{x_{14}}{\sqrt{y_{14}^2+x_{14}^2}} -\sin{a_2} \right)^2 } \right)$

then to

$q_2= 2 \frac{x_{14}^2+y_{14}^2} {x_4 x_{14} +y_4y_{14}} \arcsin\left( \frac{1}{2} \sqrt{ \left( \sin{a_{14}} -\cos{a_2} \right)^2 +\left( \cos{a_{14}} -\sin{a_2} \right)^2 } \right)$

and finally

$q_1 = 2 \frac{-x_{13}^2-y_{13}^2} {x_3x_{13}+y_3y_{13}} \arcsin\left( \frac{1}{\sqrt{2}} \sqrt{ (sin(a_{13} - a_1) + 1) } \right)$

$q_2= 2 \frac{x_{14}^2+y_{14}^2} {x_4 x_{14} +y_4y_{14}} \arcsin\left(\frac{1}{\sqrt{2}}\sqrt{1 - sin(a_{14} + a_2)} \right)$

this can possible be simplied further, but before we try, let's try and relate back to a20. a1 and a2 are already the first and second angle. a13 and a14 are angles we derived from x13 and y13. What are x13 and y13?

Stricktly they are the normalised x y position of the "solution" point, as derived from angle 1, angle 2 and a20. we're using them to measure the arc angle between that solution and angle 1 or angle 2. Turns out they aren't. I have a different simplification below.

$x_{13}=\cos\left(a_{20}\right)r_4+x_6$
$y_{13}=\sin\left(a_{20}\right)r_4+y_6$

so what are r4 and x6/y6? r4 is the radius of the "solution circle"

$r_4=\frac{1}{\sqrt{(x_4-x_3)^2+(y_4-y_3)^2}}$

and $x_3,y_3,x_4,y_4$ are the normalised vectors representing the cosines and sines of angle 1 and angle 2.

x6 and y6 represent the CENTER of the solution circle.

$x_6=0.5$
$y_6=-\frac{x_4-y_3}{-x_4+x_3-y_4+y_3}-0.5$

substitution

$x_{13}=\cos\left(a_{20}\right) \frac{1}{\sqrt{(x_4-x_3)^2+(y_4-y_3)^2}} + 0.5$
$x_{14}=1-(\cos\left(a_{20}\right) \frac{1}{\sqrt{(x_4-x_3)^2+(y_4-y_3)^2}} + 0.5)$
$y_{13}=y_{14}=\sin\left(a_{20}\right) \frac{1}{\sqrt{(x_4-x_3)^2+(y_4-y_3)^2}} +(-\frac{x_4-y_3}{-x_4+x_3-y_4+y_3}-0.5)$

and simplification

$x_{13}=\frac{\cos\left(a_{20}\right)}{\sqrt{(x_4-x_3)^2+(y_4-y_3)^2}} + 0.5$
$x_{14}=0.5 - \frac{\cos\left(a_{20}\right)}{\sqrt{(x_4-x_3)^2+(y_4-y_3)^2}}$
$y_{13}=y_{14}= \frac{\sin\left(a_{20}\right)}{\sqrt{(x_4-x_3)^2+(y_4-y_3)^2}} -\frac{x_4-y_3}{-x_4+x_3-y_4+y_3}-0.5$

and substitution

$x_{13}=\frac{\cos\left(a_{20}\right)}{\sqrt{(cos(a_2)-cos(a_1))^2+(sin(a_2)-sin(a_1))^2}} + 0.5$
$x_{14}=0.5 - \frac{\cos\left(a_{20}\right)}{\sqrt{(cos(a_2)-cos(a_1))^2+(sin(a_2)-sin(a_1))^2}}$
$y_{13}=y_{14}= \frac{\sin\left(a_{20}\right)}{\sqrt{(cos(a_2)-cos(a_1))^2+(sin(a_2)-sin(a_1))^2}} -\frac{cos(a_2)-sin(a_1)}{-cos(a_2)+cos(a_1)-sin(a_2)+sin(a_1)}-0.5$

and wolfram

$x_{13}=0.5+\frac{ cos(a_{20}) }{ \sqrt{ 2 - 2 cos(a_1 - a_2) } }$
$x_{14}=0.5-\frac{ cos(a_{20}) }{ \sqrt{ 2 - 2 cos(a_1 - a_2) } }$
$y_{13}=y_{14}= \frac{ sin(a_{20}) }{ \sqrt{ 2 - 2 cos(a_1 - a_2) } } - 0.5 \cdot cot(\frac {a_1-a_2} {2})$

we're almost able to derive a single variable function (given the v3 and v4) the function for deriving $a_{13},a_{14}$ would be

$a_{13}=atan2(y_{13},x_{13})$
$a_{14}=atan2(y_{14},x_{14})$

some substitution gives:

$a_{13}=atan2(\frac{ sin(a_{20}) }{ \sqrt{ 2 - 2 cos(a_1 - a_2) } } - 0.5 \cdot cot(\frac {a_1-a_2} {2}), 0.5+\frac{ cos(a_{20}) }{ \sqrt{ 2 - 2 cos(a_1 - a_2) } })$
$a_{14}=atan2(\frac{ sin(a_{20}) }{ \sqrt{ 2 - 2 cos(a_1 - a_2) } } - 0.5 \cdot cot(\frac {a_1-a_2} {2}) ,0.5-\frac{ cos(a_{20}) }{ \sqrt{ 2 - 2 cos(a_1 - a_2) } })$

that's about as far as it goes. Wolfram simplification already done.

sooooo

back to our q functions

$q_1=2\frac{-x_{13}^2-y_{13}^2}{x_3x_{13}+y_3y_{13}}\arcsin\left(\frac{1}{\sqrt{2}}\sqrt{\sin(a_{13}-a_1)+1}\right)$

$q_2= 2 \frac{x_{14}^2+y_{14}^2} {x_4 x_{14} +y_4y_{14}} \arcsin\left(\frac{1}{\sqrt{2}}\sqrt{1 - sin(a_{14} + a_2)} \right)$

almost there except for those x factors. How do we restate that in terms of a1 and a1? I might already be running into "cycle" issues. but let's stick with it for now. I can deal with the left factor the way I did above, with substituion. (here's where I went wrong. x13,x14, and y13 are not on the unit circle.)

$q_1 = -2sec(a_1 - a_{13}) \arcsin\left( \frac{1}{\sqrt{2}} \sqrt{(sin(a_{13} - a_1) + 1) }\right)$

$q_2=2 sec(a_2 - a_{14}) \arcsin\left(\frac{1}{\sqrt{2}}\sqrt{1 - sin(a_{14} + a_2)} \right)$

wow that's a lot simpler. I hope I didn't make a mistake along the way.

(narrator: He did) backtracking to find the mistake. this is correct

$q_1=2\frac{-x_{13}^2-y_{13}^2}{x_3x_{13}+y_3y_{13}}\arcsin\left(\frac{1}{\sqrt{2}}\sqrt{\sin(a_{13}-a_1)+1}\right)$

$q_2= 2 \frac{x_{14}^2+y_{14}^2} {x_4 x_{14} +y_4y_{14}} \arcsin\left(\frac{1}{\sqrt{2}}\sqrt{1 - sin(a_{14} + a_2)} \right)$

and

$q_1=2\frac{-x_{13}^2-y_{13}^2}{cos(a_1)x_{13}+sin(a_1)y_{13}}\arcsin\left(\frac{1}{\sqrt{2}}\sqrt{\sin(a_{13}-a_1)+1}\right)$

(i've gone back and edited some process) need to carry on subbing in the simplified x13 and y13. can that simplify?

my atan2

$h\left(y,x\right)=\left{\ \left(y+\max\left(x,0\right)\right)=0:\ \pi,\ 2\arctan\left(\frac{y}{\sqrt{2x\sqrt{x^2+y^2}+2x^2+y^2}}\right)\right}$

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment