So I got the four points of a 2 dimensional square exactly like it is displayed on this image:

image 0

Note: black&white squares displays the corners.

(!) Note: (!) Keep in mind that the corner coordinates are already sorted (Point 1 -> TOP LEFT, Point 2 - TOP RIGHT, Point 3 - BOTTOM RIGHT, Point 4 - BOTTOM LEFT) in every case (!).

The first step was drawing a green line starting at Point 4 into direction of Point 1 and drawing a red line from Point 4 into direction of Point 3 as you can see in this image:

image 1

To my question: How can I determine the missing blue line to kind of pose estimate the squares position as being displayed in the image below?

image 3

Summary: What is given are only the 4 corner points of the square shape (x, y - coordinates)! Any help would be really appreciated and what I'd like to calculate is the end-point of the blue line (marked with a red cross).

  • $\begingroup$ The cross product is probably what you want: en.wikipedia.org/wiki/Cross_product $\endgroup$ – Ethan Bolker Jun 23 '18 at 14:24
  • $\begingroup$ @EthanBolker I think the OP wants to know how to draw the blue line in 2D $\endgroup$ – Exodd Jun 23 '18 at 14:26
  • $\begingroup$ Thanks for your comment,but tbh for me the crossProduct looks like something in a 3dimensional space while I'm acting in an 2dimensional one. "the cross product or vector product [...] is a binary operation on two vectors in (!)three-dimensional space(!) - wikipedia" @EthanBolker $\endgroup$ – jonas00 Jun 23 '18 at 14:27
  • $\begingroup$ @Exodd You're probably right. $\endgroup$ – Ethan Bolker Jun 23 '18 at 14:36
  • 1
    $\begingroup$ The blue vector is the normal to the plane you are moving on. How to draw it? It depends on your projection matrix. $\endgroup$ – Cesareo Jun 23 '18 at 14:49

You didn't mention how you were mapping 3D points and vectors to 2D. I will show you how to solve the problem assuming an orthogonal projection, as the calculation is significantly more straightforward than perspective projection.

If the two (unknown) vectors making up the side of your square in 3D are $\bar u$ and $\bar v$, and the two vectors in 2D are $u=P\bar u$ and $P \bar v$, we can try to recover $\bar u$ and $\bar v$ by using the fact that they must be orthogonal and equal length in $\mathbb{R}^3$, and that $$\bar u = R(u + \alpha \hat{z})$$ for some unknown rotation matrix $R$ and scalar $\alpha$, and likewise for $v$, $$\bar v = R(v + \beta \hat{z}).$$

Since \begin{align*} \bar u \cdot \bar v &= 0\\ \|\bar u\| &= \|\bar v\| \end{align*} we have that $$u\cdot v + \alpha \beta = 0$$ $$\|u\|^2 + \alpha^2 = \|v\|^2 + \beta^2.$$ This is a system of two nonlinear equation in two variables, which can be directly solved to yield $$\beta = \frac{-(u\cdot v)}{\alpha}$$ $$\alpha^4 + (\|u\|^2-\|v\|^2)\alpha^2 - (u\cdot v)^2 = 0$$ $$\alpha = \sqrt{ \frac{\|v\|^2-\|u\|^2 + \sqrt{(\|v\|^2-\|u\|^2)^2 + 4(u\cdot v)^2}}{2}}$$ (Note that the negative option in the quadratic formula is not possible since $\alpha$ must be real.)

So now you know $\alpha$ and $\beta$. We still don't know $R$, but the vector $\bar w = \bar u \times \bar v$ perpendicular to $\bar u$ and $\bar v$ in 3D satisfies \begin{align*}\bar u \times \bar v &= R\left([u+\alpha \hat{z}] \times [v + \beta \hat{z}]\right)\\ &= R\left(\alpha v^{\perp} - \beta u^{\perp} + \|u\|\|\|v\|\hat{z}\right), \end{align*} where $u^{\perp} = \hat{z}\times u$ is the ninety-degree counterclockwise rotation of $u$ in the plane. Therefore your desired blue vector is in the direction $$\alpha v^{\perp} - \beta u^{\perp}.$$

To get the right magnitude, we scale by $\|\bar u\|/\|\bar w\|$: $$\frac{\sqrt{\|u\|^2+\alpha^2}}{\sqrt{\|v^{\perp} - \beta u^{\perp}\|^2 + \|u\|^2\|\|v\|^2}}\left(v^{\perp} - \beta u^{\perp}\right).$$

You asked for "numerical values." To be honest, I don't know that I have any more skill at plug-and-chug than you do, but if it's useful:

Let's try $u = (1,-.2)$ and $v = (.5, .8)$, which very roughly corresponds to your picture above. We expect $w$ to point left and up in the plane. Indeed using the formulas we get $$\alpha = 0.52266$$ $$\beta = -0.650518$$ Moreover $$u^{\perp} = (.2, 1),\quad v^{\perp} = (-.8, .5)$$ so that $$v^{\perp} - \beta u^{\perp} = (-0.415882, 0.847919).$$ Normalizing this direction using the formula above gives $$(-0.504623, 1.02885)$$ for the coordinates of the blue vector.

| cite | improve this answer | |
  • $\begingroup$ @jonas00 ?? You've drawn a 2D image representing some kind of 3D geometry. Therefore you have mapped from some (unknown) 3D geometry to the 2D representation in your question... $\endgroup$ – user7530 Jun 23 '18 at 15:53
  • $\begingroup$ @jonas00 you may want to read for instance people.cs.clemson.edu/~dhouse/courses/405/notes/projections.pdf $\endgroup$ – user7530 Jun 23 '18 at 15:54
  • $\begingroup$ @jonas00 Yes. But that's exactly what my answer calculates (well, I calculate the blue vector; you can calculate the red point yourself once you know the blue vector). $\endgroup$ – user7530 Jun 23 '18 at 15:55
  • $\begingroup$ Ok. You are right +1, I'm sorry for the misunderstanding because what I thought was that you provided a way to calculate the 3dimensional coordinate based on the four corners also as 3dimensional coordinates. However! Would you mind to add some numeric examples using for example these coordinates? This would really help a lot! (See i.stack.imgur.com/7gpO3.png) $\endgroup$ – jonas00 Jun 23 '18 at 16:00
  • $\begingroup$ Thanks for your update. But it looks like theres a error in your numeric-values part: For the result vector of v⊥−βu⊥ you get [−0.415882,0.847919] but for me the result would be: [-0.669896, 1.15052]. Note I got the same values for a and b using the same u & v vector. But like I've already mentioned: I got different values for v⊥−βu⊥. Would you mind to have another look? $\endgroup$ – jonas00 Jan 20 '19 at 9:53

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.