Take the 2-minute tour ×
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.

Diagram

In the diagram I've provided, how do I calculate the x,y coordinate 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|improve this question
    
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
add comment

migrated from stackoverflow.com Aug 31 '11 at 17:32

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

3 Answers

up vote 1 down vote accepted

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

$\mathbf{c}=A-B$

$\mathbf{a}=C-B$.

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

$\mathbf{x}=\frac{\mathbf{a}\cdot\mathbf{c}}{\|\mathbf{c}\|^2}\mathbf{c}$

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

share|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
    
@Emperorlou If it helped in some way up-voting is appreciated (or maybe even accepting, as it's exactly the solution you came up with, in a format more appropriate to math.stackexchange). –  Christian Rau Sep 1 '11 at 15:17
    
Christian, @Emperorlou has yet to acquire the rep necessary to upvote your answer... –  J. M. Sep 1 '11 at 15:21
add comment

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|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
add comment

I guess my question was moved to math.stackexchange.com 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: http://forums.tigsource.com/index.php?topic=16501.0

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:

p1.x-p2.x; 
p1.y-p2.y; 
p1.z-p2.z;

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|improve this answer
    
This formula is not more exact than mine, it is exactly mine, transformed from vector algebra into programming (guess how dot and $\cdot$ and len2 and $\|\cdot\|^2$ are related to each other?). But I have to admit I had a little error in my solution so you might not have seen the similarity at first (corrected it already). Even if you searched for a programming solution, it is not really hard to transform vector algebra into programming, especially when you already have functions for the dot product and the vector norm and as we're on math.se, your answer is not really neccessary. –  Christian Rau Sep 1 '11 at 15:11
add comment

Your Answer

 
discard

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.