Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

In the example picture below, I know the points $A$, $B$, $C$ & $D$. How would I go about calculating $x$, $y$, $z$ & $w$ and $O$, but as points on the actual plane itself (e.g. treating $D$ as $(0, 0)$, $A$ as $(0, 1)$, $C$ as $(1, 0)$ and $B$ as $(1, 1)$.

enter image description here

Ultimately I need to be able to calculate any arbitrary point on the plane so I'm unsure as to whether this would be possible through linear interpolation of the results above or whether I would actually just have to do this via some form of Matrix calculation? I don't really know matrix math at all!

Just looking for something I can implement in JavaScript (in an enviroment that does support matricies).

share|cite|improve this question
Two points can be used to determine and compute a line. Two nonparallel lines can be used to determine and compute an intersection. Thus you can use (I.) A and C to form AC, B and D to form BD, AC and BD to find O; (II.) A and B to form AB, C and D to form CD, AB and CD to find f1; (III.) A and D to form AD, B and C to form BC, AD and BC to find f2; (IV.) f1 and O to form f1O, f1O and BC to find x, f1O and AD to find z; (V.) f2 and O to form f2O, f2O and DC to find y, f2O and AB to find w. – anon Aug 28 '11 at 8:23
Thanks very much! I'm not sure why I didn't just see this. It certainly works to calculate the points (and I can happily work out the points relative to the plane). However this method of just using points hasn't helped me when interpolated across the whole plane for many points, so now I guess I'm going to have to bite the biscuit and go for a matrix projected transformation instead. – DiGiTaLFX Aug 28 '11 at 12:56

This should be done in terms of plane projective geometry. This means you have to introduce homogeneous coordinates. The given points $A=(a_1,a_2)$, $\ldots$, and $D=(d_1,d_2)$ have "old" homogeneous coordinates $(a_1,a_2, 1)$, $\ldots$, and $(d_1,d_2,1)$ and should get "new" homogeneous coordinates $\alpha(0,1,1)$, $\beta(1,1,1)$, $\gamma(1,0,1)$, and $\delta(0,0,1)$. There is a certain $(3\times 3)$-matrix $P:=[p_{ik}]$ (determined up to an overall factor) that transforms the old coordinates into the new ones. To find this matrix you have twelve linear equations in thirteen variables which is just right for our purpose. (The values of $\alpha$, $\ldots$, $\delta$ are not needed in the sequel.)

After the matrix $P$ has been determined the new affine coordinates $(\bar x, \bar y)$ of any point $(x,y)$ in the drawing plane are obtained by applying $P$ to the column vector $(x,y,1)$. This results in a triple $(x',y',z')$, whereupon one has $$\bar x={x'\over z'}\ ,\quad \bar y={y'\over z'}\ .$$

share|cite|improve this answer

This isn't so bad, so that's good. Your suggested set of points, however, do not submit to the same sort of analysis as what I'm about to give because it's a square - so the sides are parallel (so the f1 and f2 are... inconvenient, even in the projective plane; if you know projective geometry, mention it, and I'll update).

The general process is to find the equations of lines, find where they intersect, and then make more lines, and find where they intersect. Ok? Great.

First, the point $O$ is nothing more than the midpoint of DB. Perhaps the figure in general is not symmetric, in which case it's the intersection of DB and AC. Say the coordinates of A are $\left[ \begin{array}{cc} a_x \\ a_y \end{array} \right]$, the coordinates of B are $\left[ \begin{array}{cc} b_x \\ b_y \end{array} \right]$ and so on.

Then the lines DB and AC can be parameterized by the equations

$\overline{DB} = \left[ \begin{array}{cc} b_x \\ b_y \end{array} \right] + \left( \left[ \begin{array}{cc} d_x \\ b_y \end{array} \right] - \left[ \begin{array}{cc} b_x \\ b_y \end{array} \right] \right)t$

$\overline{AC} = \left[ \begin{array}{cc} a_x \\ a_y \end{array} \right] + \left( \left[ \begin{array}{cc} c_x \\ c_y \end{array} \right] - \left[ \begin{array}{cc} a_x \\ a_y \end{array} \right] \right)s$

Now you set equal and solve for s and t. How? Considering x and y components separately, you have two equations in 2 variables - use a matrix.

$\left[ \begin{array}{cc} d_x - b_x & c_x - a_x \\ d_y - b_y & c_y - a_y \end{array} \right] \left[ \begin{array}{cc} t \\ s \end{array} \right] = \left[ \begin{array}{cc} b_x - a_x \\ b_y - a_y \end{array} \right]$

And this procedure will give you the intersection of those two lines. In fact, this will give you the intersection between any two non-parallel lines. Good.

So with this, we found the point $O$. Do this with the lines AD and BC to find their focal point, f2. Repeat with the lines AD and BC to find their focal point, f1. Then we can repeat with the lines $\overline{f_1O}$ and $\overline{AD}$ to find z. $\overline{f_1O}$ and $\overline{BC}$ to find x. And because I've given almost everything away, rinse, wash, and repeat for w and y.

Does that make sense?

share|cite|improve this answer
OK, yes I think that does make sense. Now would there be an easy way to calculate the points on the actual plane using matrices as well? So e.g. A = (0,1) B = (1,1) I would like to know what w is. Then, is it possible to work out say a 20 x 20 grid of points on this plane too?! – DiGiTaLFX Aug 28 '11 at 14:33
@DiGi I don't understand what you are saying to me. Can you rephrase? – mixedmath Aug 28 '11 at 17:16
Hmmm I think I'm attempting this in the wrong way. Basically I have a shape with points A, B, C, D on my computer screen. I'm attempting to fake perspective onto it by distorting the texture. So the point O for the texture would normally be (0.5, 0,5). I'd like to work out how I translate that so it appears to be further into the distance. So in the example picture O would have coordinates closer to A (which in texture coordinates is (0, 1) even though it has screen coordinates of different values. Does that make any more sense? – DiGiTaLFX Aug 30 '11 at 18:26

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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