Sign up ×
Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.


In the diagram, I've provided, how do I calculate the $x$, $y$ coordinates of $F$ if the points $A$, $B$, $C$ are arbitrary points on a grid?

I'm looking for a formula to solve $F's$ $X$ axis and another formula to solve $F's$ $Y$ axis.

share|cite|improve this question

migrated from Aug 31 '11 at 17:32

This question came from our site for professional and enthusiast programmers.

Do you know anything about the angles or lengths of the sides of the triangles? – Dan W Aug 31 '11 at 17:26
@Dan The X/Y coords for A,B,C is known so I could find the lengths of any side. – Emperorlou Aug 31 '11 at 17:28
@Dan: I can't find x or Y until I know F. And if I knew that, I'd be good anyway. I'll try creating the question in math as you suggested. Thanks – Emperorlou Aug 31 '11 at 17:31

3 Answers 3

up vote 1 down vote accepted

I hope you are fit in simple vector algebra: First you compute the vectors



By projecting $\mathbf{a}$ onto $\mathbf{c}$ you get the vector $\mathbf{x}$


from which you can easily obtain the vector $\mathbf{y}=\mathbf{c}-\mathbf{x}$ and the point $F=B+\mathbf{x}$.

share|cite|improve this answer
This answer was a lot easier for me to piece together in my head since it used the symbols from my diagram. I appreciate it! I did however find a more exact formula for what I'm trying to do elsewhere on the web and I've posted it. – Emperorlou Sep 1 '11 at 2:33

I guess my question was moved to a bit prematurely since I'm actually looking for an answer in "computer" rather than in "math" (since I'm not fluent in math :p).

I managed to find a website that broke down the answer in a way I was able to easily digest and here is a link to the answer was the best fit for me:

In this pseudo code, p1, p2 and p3 are all vectors (eg p1.x, p1.y, p1.z). It should work with a 2D or 3D vector.

For those unfamiliar with dealing with vectors, when I write p1-p2, literally it means:


This code seems to be working for me though

The important code bits are as follows (in pseudo code):

function getX(Vector p1, Vector p2, Vector p3):float
    Vector e = p2 - p1;
    return p1.x + e.x * dot(e, p3 - p1) / len2(e);

function len2(v):float
    return v.x*v.x + v.y*v.y;
share|cite|improve this answer

All you need do is to project the point C onto the line connecting A and B.

In general, the projection of a point $(c,d)$ onto a line $y=mx+b$ is

$$\begin{align*} x&=\frac{md + c - mb}{m^2 + 1}\\ y&=\frac{m^2 d + mc + b}{m^2 + 1} \end{align*}$$

share|cite|improve this answer
Thanks for the answer, I'm sure its right but its hard for me to translate that into something I can use with pure x/y co-ords as my variables. I've posted another answer I found on the net that is a bit closer to my world. But thanks anyway! – Emperorlou Sep 1 '11 at 2:31

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.