4

I have the following problem: problem

in 2D space.
I have quadrilateral which have 2 of angles = 90 degree
And 2 non unit vectors h1 and h2. (Have length and direction)
We, also, have point P where h2 and diag begins.

I need to find diagonal vector diag. I need solution that use only vector operations(no trigonometric functions) if possible.

tower120
  • 155

1 Answers1

1

Observation: the thing you've called "diag", which I'll call $2v$, is the diameter of a circle. Thus $v$ denotes the radius vector. Let's call the left end of the diameter -- the starting point of $h_2$ -- by the name $P$, and the right end by the name $S$.

The circle with diameter $PS$ also contains the endpoint $Q = P + h_2$ of the vector $h_2$. Why? Because a triangle inscribed in a circle with two vertices at the ends of a diameter has a right angle at the third vertex, and conversely, gives a right triangle, a circle built so that the triangle's hypotenuse is its diameter will contain the third vertex (at which the angle will of course be 90 degrees, by the previous statement.)

Furthermore, by moving the vector you've called $h_1$ so that it starts at $P$ and ends at the point $R = P + h_1$, we get another right triangle $PRS$ erected on the diagonal.

If we write down the midpoints of $PQ$ and $PR$, we can express the perpendicular bisectors of the segments $PQ$ and $PR$, find their intersection, $C$, and then $v = C - P$, and the diagonal you're seeking is $2v$. Let's do it.

$M_1 =$ midpoint of $PQ = \frac{P+Q}{2} = P + \frac{1}{2} h_2$.

$M_2 =$ midpoint of $PR = P + \frac{1}{2} h_1$.

Now \begin{align} (C - M_1) \cdot h_2 &= 0, \text{ because $C$ lies on the perp bisector of $PQ$} \\ (C - M_2) \cdot h_1 &= 0 \text{ similarly} \end{align}

Substituting, and using the fact that $C - P = v$, by the definition of $v$, we get

$$ (C - (P + \frac{1}{2} h_2)) \cdot h_2 = 0 \\ (C - (P + \frac{1}{2} h_1)) \cdot h_1 = 0 $$ so $$ ((C - P) - \frac{1}{2} h_2) \cdot h_2 = 0 \\ ((C - P) - \frac{1}{2} h_1) \cdot h_1 = 0 $$ so $$ (v - \frac{1}{2} h_2) \cdot h_2 = 0 \\ (v - \frac{1}{2} h_1) \cdot h_1 = 0 $$ so $$ v \cdot h_2 = \frac{1}{2} h_2 \cdot h_2 \\ v \cdot h_1 = \frac{1}{2} h_1 \cdot h_1 $$ Now write $$ v = a h_1 + b h_2 $$ and plug in to solve. To simplify, let $q_{ij} = h_i \cdot h_j$. Then $$ (a h_1 + b h_2) \cdot h_2 = \frac{1}{2} h_2 \cdot h_2 \\ (a h_1 + b h_2) \cdot h_1 = \frac{1}{2} h_1 \cdot h_1 $$

$$ a q_{12} + b q_{22} = \frac{1}{2} q_{22} \\ a q_{11} + b q_{21} = \frac{1}{2} q_{11} $$ In matrix form, that says that $$ \begin{bmatrix} a & b \end{bmatrix} \begin{bmatrix} q_{11} & q_{12} \\ q_{21} & q_{22} \end{bmatrix} = \frac{1}{2}\begin{bmatrix} q_{11} & q_{22} \end{bmatrix} $$ so $$ \begin{bmatrix} a & b \end{bmatrix} = \frac{1}{2}\begin{bmatrix} q_{11} & q_{22}\end{bmatrix} \begin{bmatrix} q_{11} & q_{12} \\ q_{21} & q_{22} \end{bmatrix}^{-1} $$ from which you can recover $v$ and then the diagonal, which is $2v$.

I'm sure there's an easier way, but this gets you there.

ADDITIONAL REMARKS: Suppose that we let $k_1$ be $h_1$, rotated 90 degrees in the plane, and similarly for $k_2$ and $h_2$. (If $h_1 = [s, t]$, then $k_1 = [-t, s]$.) Then we can write $v = c k_1 + d k_2$. Now solving $$ v \cdot h_2 = \frac{1}{2} h_2 \cdot h_2 \\ v \cdot h_1 = \frac{1}{2} h_1 \cdot h_1 $$ gets easy: $$ (c k_1 + d k_2) \cdot h_2 = \frac{1}{2} h_2 \cdot h_2 \\ (c k_1 + d k_2) \cdot h_1 = \frac{1}{2} h_1 \cdot h_1 $$ becomes $$ c = \frac{1}{2} \frac{h_2 \cdot h_2}{k_1 \cdot h_2} \\ d = \frac{1}{2} \frac{h_1 \cdot h_1}{k_2 \cdot h_1} $$ and so $$ v = \frac{1}{2} \frac{h_2 \cdot h_2}{k_1 \cdot h_2} k_1 + \frac{1}{2} \frac{h_1 \cdot h_1}{k_2 \cdot h_1} k_2. $$ You can't get much more vector-based than that!

Note: It turns out that by trig identities, $k2 \cdot h_1 = - k_1 \cdot h_2$, so the expression above simplifies a little: $$ v = \frac{1}{2} \frac{1}{k_1 \cdot h_2} \left( (h_2 \cdot h_2) k_1 - (h_1 \cdot h_1) k_2 \right). $$

And since the thing you want is $2v$, you can even get rid of the $\frac{1}{2}$:

$$ diag = \frac{1}{k_1 \cdot h_2} \left( (h_2 \cdot h_2) k_1 - (h_1 \cdot h_1) k_2 \right). $$

John Hughes
  • 93,729
  • Maybe I not really strong with math. But I try to understand your proof. And... Why you say that "diag" is diamatere of the circle? This quadrilateral can not be inscribed in a circle. And.. Can you rephrase "erected on the diagonal."? – tower120 Mar 25 '14 at 00:30
  • This is almost my case http://math.stackexchange.com/questions/61305/creating-a-special-vector-from-two-vectors?rq=1, but in my case AB <> AC (not equal) – tower120 Mar 25 '14 at 00:31
  • Sure: From my 10th grade geometry class, if you have a diameter of a circle with center $C$ and the endpoints of the diagonal are $A$ and $B$, and $D$ is any other point of the circle, then $ADB$ is a right triangle, with the right angle at $D$. Conversely, for any right triangle $ADB$ with the right angle at $D$, a circle whose diameter is the segment $AB$ will pass through the point $D$ (and I would say that "the triangle $ABD$ was erected on the segment $AB$"). Thus in your diagram, a circle whose diameter is the segment you've called "diag" will pass through the two right-angle corners. – John Hughes Mar 25 '14 at 02:09
  • "and the endpoints of the diagonal are A and B" - What is "diagonal" in terms of circle, you mean diameter? From my point of view, only polygons can have diagonal http://en.wikipedia.org/wiki/Diagonal – tower120 Mar 25 '14 at 09:22
  • And... in your answer. v is circle radius, right (vectorized)? – tower120 Mar 25 '14 at 09:43
  • And if v is radius vector. Why v=2(C−P), where C is circle center and P is radius/diameter endpoint (radius*2 = diameter)? Shouldn't it be v = (C-P) ? – tower120 Mar 25 '14 at 10:03
  • By the way, later you substitute C-P with v, so I think v=2(C−P) ,at the begin, is just typo. – tower120 Mar 25 '14 at 10:12
  • Thanks for all the comments; I'll fix things up---I should have spent more time before writing. – John Hughes Mar 25 '14 at 12:52
  • Edits made as suggested. – John Hughes Mar 25 '14 at 13:07
  • And you sure about [q11, q12] order (row/column)? In last equation. – tower120 Mar 25 '14 at 14:43
  • I'm fairly sure. To make the matrix equation, you need to swap the order of the two equations above (which I did just to make the indexes work out nicely: it's best if the $1,2$-entry of $Q$ is in the $(1, 2)$ position. :) – John Hughes Mar 25 '14 at 14:46
  • It would be almost perfect if it would be possible to get rid from matrix inverse. You see, I write vertex shader for GLSL ES 2.0, and it does not have inverse function.... – tower120 Mar 25 '14 at 18:54
  • The inverse of the matrix $\begin{bmatrix} a & c \ b & d \end{bmatrix}$ is just $\frac{1}{ad - bc}\begin{bmatrix} d & -c \ -b & a \end{bmatrix}$. So now you don't need a matrix inverse function. :) – John Hughes Mar 26 '14 at 00:53
  • Its not "just" - its + 4-6 cycles (while matrix multiplication is cheap). Which is make my shader even more uncheap. By the way mathematica give me very intresting solve of $$ v \cdot h_2 = \frac{1}{2} h_2 \cdot h_2 \ v \cdot h_1 = \frac{1}{2} h_1 \cdot h_1 $$ but not in linear algebra style, if I can't pack it back to linear view, I'll stay with your answer :) – tower120 Mar 26 '14 at 01:24
  • I'm not surprised that Mathematica gave a simpler answer. Indeed, thinking about it for a moment, see the edits above after "ADDITIONAL REMARKS". (And perhaps mark my answer as correct...) – John Hughes Mar 26 '14 at 02:27