3
$\begingroup$

Diagram

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.

$\endgroup$
3
  • $\begingroup$ Do you know anything about the angles or lengths of the sides of the triangles? $\endgroup$
    – Dan W
    Aug 31, 2011 at 17:26
  • $\begingroup$ @Dan The X/Y coords for A,B,C is known so I could find the lengths of any side. $\endgroup$
    – Emperorlou
    Aug 31, 2011 at 17:28
  • $\begingroup$ @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 $\endgroup$
    – Emperorlou
    Aug 31, 2011 at 17:31

3 Answers 3

1
$\begingroup$

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}$.

$\endgroup$
1
  • $\begingroup$ 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. $\endgroup$
    – Emperorlou
    Sep 1, 2011 at 2:33
1
$\begingroup$

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*}$$

$\endgroup$
1
  • $\begingroup$ 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! $\endgroup$
    – Emperorlou
    Sep 1, 2011 at 2:31
0
$\begingroup$

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;
}
$\endgroup$
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .