7
$\begingroup$

I have a triangle $ABC$ with side lengths $a,b,c$ (edges $BC, CA, AB$ respectively).

I have a point $p$ with barycentric coordinates $u:v:w$.

These are normalised: $u+v+w=1$. $1:0:0$ corresponds to point $A$, $0:1:0$ is $B$ etc.

Is there a simple expression for the distance $d$ of the point $p$ from $A$ ?

(My initial naive guess based on $d(1:0:0)=0, d(0:1:0)=b, d(0:0:1)=c$ was that $d$ was linear $d(u,v,w)=v*b+w*c$ but this is clearly wrong as in the case of an equilateral triangle $a=b=c=1$ it returns $d=2/3$ for the centroid ($u:v:w = 1/3:1/3:1/3$), when the correct answer should be $1/\sqrt 3$ (the radius of the circumscribed circle)).

$\endgroup$
4
  • 1
    $\begingroup$ This question seems not suitable for MO (not research level, this only uses Pythagore theorem), please read the FAQ. There is a formula, that you can devise by assuming $A$ is at the origin, $B$ is on the $x$-axis. The coordinates of $C$ are then easy to compute in terms of $a,b,c$, than you get the coordinates of your point. The distance is then given by the usual Euclidean formula. $\endgroup$ Aug 25, 2010 at 13:40
  • $\begingroup$ better yet, try it on math.stackexchange.com $\endgroup$ Aug 25, 2010 at 14:12
  • $\begingroup$ Sorry! Was completely unaware of math.stackexchange.com! Suspected I was a bit out of my depth here. Can it be migrated over ? $\endgroup$
    – timday
    Aug 25, 2010 at 14:30
  • $\begingroup$ not AFAIK. but it looks like you got an answer, so it's all good :) $\endgroup$ Aug 25, 2010 at 17:46

5 Answers 5

4
$\begingroup$

There isn't really a simple formula, but you can use vector methods. Let $\mathbf{a}$, $\mathbf{b}$ and $\mathbf{c}$ be position vectors of the vertices. A point $P$ with normalized barycentric coordinates $(u,v,w)$ has position vector $\mathbf{p}=u\mathbf{a}+v\mathbf{b}+w\mathbf{c}$. Therefore $\mathbf{p}-\mathbf{a}=v(\mathbf{b}-\mathbf{a})+w(\mathbf{c}-\mathbf{a})$. This leads to $$|AP|^2=v^2|AB|^2+w^2|AC|^2+2vw|AB||AC|\cos\alpha$$ where $\alpha$ is the angle at $A$. Of course one can express $|AB||AC|\cos\alpha$ in terms of the three side-lengths of the triangle using the cosine rule.

This shows that neither $|AP|$ nor $|AP|^2$ is a linear function of the barycentric coordinates (actually this is geometrically evident too). But there is a simpler formula for the distance of $P$ to a given side of the triangle.

$\endgroup$
6
$\begingroup$

Robin gives the correct formula, but not in the simplest form. Since $$a^2=b^2+c^2-2bc\cos\alpha,$$ the desired distance satisfies $$d^2=(bw)^2+(cv)^2+vw(b^2+c^2-a^2).$$ A little manipulation also yields $$d^2=(bw-cv)^2+vw((b+c)^2-a^2)$$

$\endgroup$
2
$\begingroup$

There actually is a delightful formula -- see page 11 at http://www.mit.edu/~evanchen/handouts/bary/bary-full.pdf

Your displacement vector is $(u-1,v,w)$, giving $d^2=-(a^2vw+b^2w(u-1)+c^2v(u-1))$

$\endgroup$
1
$\begingroup$

So there is a paper A Hybrid GPU Rendering Pipeline for Alias-Free Hard Shadows

That claims to calculate the distance to a triangle $d(\omega,T)$ efficiently, they

resort to some tricks based on the concepts of barycentric coordinates

they describe the squared distance between a point $w$ and some vertex $v_i$ of the triangle $T$ as

$d(\omega,v_i)^2=\left\Vert \omega-v_{i}\right\Vert=\lambda_{i-1}^{2}\left\Vert e_{i-1}\right\Vert ^{2}+\lambda_{i+1}^{2}\left\Vert e_{i+1}\right\Vert ^{2}-2\lambda_{i-1}\lambda_{i+1}\left(e_{i-1}\cdot e_{i}\right)$

There is a derivation in the paper.

I think using the notation you described it'd look something like this

$d(p,A)^2=\left\Vert p-A\right\Vert=w^2b^2+v^2a^2-2wv(CA\cdot AB)$

but I'd check the math just to be sure

$\endgroup$
0
$\begingroup$

Following from Benoît Kloeckner's comment above,

Place the points at $A=(0,0)$ at the origin, $B=(c,0)$ on the x-axis with the distance $|AB|=c$, and $C=(x,y)$, where we now want to satisfy $|AC|=b$ and $|BC|=a$.

Simple application of the Pythagorean theorem leads to

$x^2+y^2 = b^2$ and $(x-c)^2+y^2 = a^2$

as the two constraints to be applied.

Expanding and subtracting the two equations:

$x^2-2cx+c^2+y^2=a^2$ and $x^2 + y^2 =b^2$

$2cx-c^2=b^2-a^2$

$2cx = (b^2-a^2+c^2)$

$x = \frac{b^2-a^2+c^2}{2c}$

Now you can define $y$ in terms of $x$.

Simply scale the points $\vec{A}=(0,0), \vec{B}=(0,c)$, and $\vec{C}=(x,y)$ by their respective $(u,v,w)$ barycentric coordinates to get $D=(x_D,y_D)$ as a function of $a,b,c,u,v,w$, apply the Pythagorean theorem again to get $d = |\vec{D}|$ = the square root of $(x_d)^2 + (y_d)^2$. This last step shouldn't need to be spelled out for you, but $\vec{D}=u\vec{A}+v\vec{B}+w\vec{C}$

$\endgroup$
1
  • $\begingroup$ I would have added this as a comment, as Benoît Kloeckner did above; however, I did not have commenting ability at that time. Thus I replied as an answer. $\endgroup$ Aug 26, 2010 at 7:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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