1
$\begingroup$

Based on a diagram (the numbers are just examples to aid in identification) I came up with the following equations:

$$ \begin{array}{l} ( x+y)\csc (\alpha )=( z+a)\csc (\alpha +\theta )\\ y\csc (\beta )=( z+a)\csc (\beta +\theta )\\ ( x+y)\csc (\gamma )=a\csc (\gamma +\theta )\\ y\csc (\delta )=a\csc (\delta +\theta ) \end{array} $$

which I reduced to

$$\theta = \arcsin\left(\frac{a}{\sec( \delta ) y}\right) -\delta =\arcsin\left(\frac{a}{\sec( \gamma )( x+y)}\right) -\gamma =\arcsin\left(\frac{z+a}{\sec( \beta ) y}\right) -\beta =\arcsin\left(\frac{z+a}{\sec( \alpha )( x+y)}\right) -\alpha$$

Solve for $x$ and eliminate $y$, $z$, and $\theta$. The remaining letters, $\alpha$, $\beta$, $\gamma$, $\delta$, and $a$, are constant. This is for a physical device, so all the lengths are positive, the angles except $\theta$ are between $0$ and $\frac\tau4=\frac\pi2=90^\circ$, $\theta$ is between $0$ and $\frac\tau2=\pi=180^\circ$, and close formula-based approximations are fine.

Mathematica (via the free plan for Wolfram Programming Lab) either timed out or ran out of memory: https://lab.wolframcloud.com/env/solly.ucko/SteepleMeasurer%201000.nb

SymPy said it couldn't solve this kind of equation:

Python 3.7.4 (tags/v3.7.4:e09359112e, Jul  8 2019, 19:29:22) [MSC v.1916 32 bit
(Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from sympy import *
>>> alpha, beta, gamma, delta, a, x, y, z, theta = symbols('alpha, beta, gamma,
delta, a, x, y, z, theta')
>>> parsed = parse_latex("\arcsin\left(\frac{a}{\sec( \delta ) y}\right) -\delta
 =\arcsin\left(\frac{a}{\sec( \gamma )( x+y)}\right) -\gamma =\arcsin\left(\frac
{z+a}{\sec( \beta ) y}\right) -\beta =\arcsin\left(\frac{z+a}{\sec( \alpha )( x+
y)}\right) -\alpha ")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'parse_latex' is not defined
>>> from sympy.parsing.latex import parse_latex
>>> parsed = parse_latex("\arcsin\left(\frac{a}{\sec( \delta ) y}\right) -\delta
 =\arcsin\left(\frac{a}{\sec( \gamma )( x+y)}\right) -\gamma =\arcsin\left(\frac
{z+a}{\sec( \beta ) y}\right) -\beta =\arcsin\left(\frac{z+a}{\sec( \alpha )( x+
y)}\right) -\alpha ")
Traceback (most recent call last):
  File "C:\Users\Solly\AppData\Local\Programs\Python\Python37-32\lib\site-packag
es\antlr4\Lexer.py", line 128, in nextToken
    ttype = self._interp.match(self._input, self._mode)
  File "C:\Users\Solly\AppData\Local\Programs\Python\Python37-32\lib\site-packag
es\antlr4\atn\LexerATNSimulator.py", line 97, in match
    return self.matchATN(input)
  File "C:\Users\Solly\AppData\Local\Programs\Python\Python37-32\lib\site-packag
es\antlr4\atn\LexerATNSimulator.py", line 126, in matchATN
    predict = self.execATN(input, next)
  File "C:\Users\Solly\AppData\Local\Programs\Python\Python37-32\lib\site-packag
es\antlr4\atn\LexerATNSimulator.py", line 191, in execATN
    return self.failOrAccept(self.prevAccept, input, s.configs, t)
  File "C:\Users\Solly\AppData\Local\Programs\Python\Python37-32\lib\site-packag
es\antlr4\atn\LexerATNSimulator.py", line 250, in failOrAccept
    raise LexerNoViableAltException(self.recog, input, self.startIndex, reach)
antlr4.error.Errors.LexerNoViableAltException: LexerNoViableAltException('')

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\Solly\AppData\Local\Programs\Python\Python37-32\lib\site-packag
es\sympy\parsing\latex\__init__.py", line 34, in parse_latex
    return _latex.parse_latex(s)
  File "C:\Users\Solly\AppData\Local\Programs\Python\Python37-32\lib\site-packag
es\sympy\parsing\latex\_parse_latex_antlr.py", line 85, in parse_latex
    relation = parser.math().relation()
  File "C:\Users\Solly\AppData\Local\Programs\Python\Python37-32\lib\site-packag
es\sympy\parsing\latex\_antlr\latexparser.py", line 390, in math
    self.enterRule(localctx, 0, self.RULE_math)
  File "C:\Users\Solly\AppData\Local\Programs\Python\Python37-32\lib\site-packag
es\antlr4\Parser.py", line 366, in enterRule
    self._ctx.start = self._input.LT(1)
  File "C:\Users\Solly\AppData\Local\Programs\Python\Python37-32\lib\site-packag
es\antlr4\CommonTokenStream.py", line 61, in LT
    self.lazyInit()
  File "C:\Users\Solly\AppData\Local\Programs\Python\Python37-32\lib\site-packag
es\antlr4\BufferedTokenStream.py", line 186, in lazyInit
    self.setup()
  File "C:\Users\Solly\AppData\Local\Programs\Python\Python37-32\lib\site-packag
es\antlr4\BufferedTokenStream.py", line 189, in setup
    self.sync(0)
  File "C:\Users\Solly\AppData\Local\Programs\Python\Python37-32\lib\site-packag
es\antlr4\BufferedTokenStream.py", line 111, in sync
    fetched = self.fetch(n)
  File "C:\Users\Solly\AppData\Local\Programs\Python\Python37-32\lib\site-packag
es\antlr4\BufferedTokenStream.py", line 123, in fetch
    t = self.tokenSource.nextToken()
  File "C:\Users\Solly\AppData\Local\Programs\Python\Python37-32\lib\site-packag
es\antlr4\Lexer.py", line 130, in nextToken
    self.notifyListeners(e)             # report error
  File "C:\Users\Solly\AppData\Local\Programs\Python\Python37-32\lib\site-packag
es\antlr4\Lexer.py", line 285, in notifyListeners
    listener.syntaxError(self, None, self._tokenStartLine, self._tokenStartColum
n, msg, e)
  File "C:\Users\Solly\AppData\Local\Programs\Python\Python37-32\lib\site-packag
es\antlr4\error\ErrorListener.py", line 60, in syntaxError
    delegate.syntaxError(recognizer, offendingSymbol, line, column, msg, e)
  File "C:\Users\Solly\AppData\Local\Programs\Python\Python37-32\lib\site-packag
es\sympy\parsing\latex\_parse_latex_antlr.py", line 59, in syntaxError
    raise LaTeXParsingError(err)
sympy.parsing.latex.errors.LaTeXParsingError: I don't understand this
ight) -lpha csin\left(♀rac{z+a}{\sec( lpha )( x+y)}+y)}
^
>>> parsed = parse_latex("\arcsin\left(\frac{a}{\sec( \delta ) y}\right) -\delta
 =\arcsin\left(\frac{a}{\sec( \gamma )( x+y)}\right) -\gamma =\arcsin\left(\frac
{z+a}{\sec( \beta ) y}\right) -\beta =\arcsin\left(\frac{z+a}{\sec( \alpha )( x+
y)}\right) -\alpha ")
KeyboardInterrupt
>>> parsed = parse_latex("\\arcsin\\left(\\frac{a}{\\sec( \\delta ) y}\\right) -
\\delta =\\arcsin\\left(\\frac{a}{\\sec( \\gamma )( x+y)}\\right) -\\gamma =\\ar
csin\\left(\\frac{z+a}{\\sec( \\beta ) y}\\right) -\\beta =\\arcsin\\left(\\frac
{z+a}{\\sec( \\alpha )( x+y)}\\right) -\\alpha ")
>>> parsed
False
>>> ex1, ex2, ex3, ex4 = map(parse_latex, "\\arcsin\\left(\\frac{a}{\\sec( \\del
ta ) y}\\right) -\\delta =\\arcsin\\left(\\frac{a}{\\sec( \\gamma )( x+y)}\\righ
t) -\\gamma =\\arcsin\\left(\\frac{z+a}{\\sec( \\beta ) y}\\right) -\\beta =\\ar
csin\\left(\\frac{z+a}{\\sec( \\alpha )( x+y)}\\right) -\\alpha ".split("="))
>>> ex1, ex2, ex3, ex4
(-delta + asin(left(right*(a/((y*sec(delta)))))), -gamma + asin(left(right*(a/((
(x + y)*sec(gamma)))))), -beta + asin(left(right*((a + z)/((y*sec(beta)))))), -a
lpha + asin(left(right*((a + z)/(((x + y)*sec(alpha)))))))
>>> solve([ex1-ex2, ex2-ex3, ex3-ex4])
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\Solly\AppData\Local\Programs\Python\Python37-32\lib\site-packag
es\sympy\solvers\solvers.py", line 1173, in solve
    solution = _solve_system(f, symbols, **flags)
  File "C:\Users\Solly\AppData\Local\Programs\Python\Python37-32\lib\site-packag
es\sympy\solvers\solvers.py", line 1937, in _solve_system
    raise NotImplementedError('could not solve %s' % eq2)
NotImplementedError: could not solve -delta + gamma + asin(left(right*(a/((y*sec
(delta)))))) - asin(left(right*(a/(((x + y)*sec(gamma))))))
>>>
```
$\endgroup$
  • $\begingroup$ I see four equations and nine unknowns. Which variables did you intend to solve for and/or which did you intend to leave as parameters? $\endgroup$ – Eric Towers Dec 7 '19 at 17:06
  • $\begingroup$ @EricTowers $\alpha$, $\beta$, $\gamma$, $\delta$, and $a$ are constants/parameters. $\endgroup$ – Solomon Ucko Dec 7 '19 at 17:07
  • $\begingroup$ Style comment: Cosecant? Really? Who writes everything in cosecants? $\endgroup$ – Eric Towers Dec 7 '19 at 19:08
  • $\begingroup$ @EricTowers Feel free to replace $\csc$ with $/\sin$. $\endgroup$ – Solomon Ucko Dec 7 '19 at 19:50
  • 1
    $\begingroup$ This matters because you have just eliminated eighty extremal cases that the computer algebra systems you were using had to solve. (That is, you have just now reduced the size of the problem to about 1.25% of the size of the problem you described to SymPy.) $\endgroup$ – Eric Towers Dec 7 '19 at 20:35
1
$\begingroup$

I'm going to replace $a$ with $w$, so that I can define $$a := \cot\alpha \qquad b := \cot\beta \qquad c := \cot\gamma \qquad d := \cot\delta \qquad t := \cot\theta \tag{0}$$


We can readily solve, say, the first three equations as a linear system in $x$, $y$, $z$ to get $$\begin{align} x &= w\,\frac{\sin(\alpha-\beta) \sin\gamma}{\sin(\gamma-\alpha)\sin(\beta + \theta)} &&= w\,\frac{b-a}{ (a-c) (b + t)\sin\theta} \\[4pt] y &= w\,\frac{\sin\beta \sin\gamma \sin(\alpha+\theta)}{\sin(\gamma-\alpha)\sin(\beta+\theta)\sin\theta} &&= w\,\frac{a + t}{(a-c)(b+t)\sin\theta} \\[4pt] z &= w\,\frac{\sin\alpha \sin(\gamma+\theta)}{\sin(\gamma-\alpha) \sin\theta} &&= w\,\frac{c+t}{a-c} \end{align}\tag{1}$$

If $w=0$, we're done. Otherwise, substituting these into the final equation, and dividing through by non-zero $w$ quickly yields

$$t = -\frac{a d - b c}{a-b-c+d} \tag{2}$$ so that $$b+t = -\frac{(a-b)(d-b)}{a-b-c+d} \qquad c+t = -\frac{(a-c)(d-c)}{a-b-c+d} \tag{3}$$ $$\sin\theta = \frac{1}{\sqrt{1+t^2}} = \frac{|a-b-c+d|}{\sigma} \qquad \sigma := \sqrt{(a-b-c+d)^2+(a d - b c)^2} \tag{4}$$ and then

$$\begin{align} x &= \sigma w\,\frac{\operatorname{sgn}(a-b-c+d)}{(c - a) (b - d)} \\[4pt] y &= \sigma w\,\frac{1}{(b - d)\,|a-b-c+d|} \\[4pt] z &= \phantom{\sigma}w\,\frac{c-d}{a-b-c+d} \end{align}\tag{$\star$}$$

It may be worth noting these relations:

$$\begin{align} (x:y) &= (a-b-c+d:c-a) \\[4pt] (w:z) &= (a-b-c+d :c-d) \end{align} \tag{5}$$

| cite | improve this answer | |
$\endgroup$
  • 1
    $\begingroup$ Yay, it works! Thanks! $\endgroup$ – Solomon Ucko Dec 8 '19 at 2:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.