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.

I'm trying to draw with Java programming language a Koch fractal to emulate a winter snowflake (it is winter, yeah! : )

If I have 2 points P1(0,0) and P2(10, 0), find P3 of the equilateral triangle P1-P2-P3. It's quite easy, I take the midpoint of P1-P2, and add the height of an equilateral triangle ($h=\frac{l}{2}\sqrt{3}$).

So:

$$P3.x = (P2.x-P1.x)/2$$

$$P3.y = (P2.y-P1.y)/2 + \frac{P2.y-P1.y}{2}\sqrt{3}$$

But what if I have 2 arbitrary points? How can I get the third? For example if I have P1(10, 25) and P2(42, 79) ?

Sorry if I haven't used the best notation and if don't know how to draw a nice figure to better explanation in latex!

share|improve this question
    
You want $P3.x=(P2.x+P1.x)/2$. It doesn't matter when $P1.x=0$ –  Ross Millikan Dec 19 '11 at 22:39

5 Answers 5

up vote 7 down vote accepted

The matrices for rotation by $\pi/3$ and $-\pi/3$ are $$ M_+=\begin{bmatrix}1/2&\sqrt{3}/2\\-\sqrt{3}/2&1/2\end{bmatrix} $$ and $$ M_-=\begin{bmatrix}1/2&-\sqrt{3}/2\\\sqrt{3}/2&1/2\end{bmatrix} $$ equilateral triangles

yielding the vertices for the two equilateral triangles: $$ \begin{align} &\begin{bmatrix}x_1&y_1\end{bmatrix}+\begin{bmatrix}x_2-x_1&y_2-y_1\end{bmatrix}\begin{bmatrix}1/2&\sqrt{3}/2\\-\sqrt{3}/2&1/2\end{bmatrix}\\&=\frac{1}{2}\begin{bmatrix}(x_2+x_1)-\sqrt{3}(y_2-y_1)&(y_2+y_1)+\sqrt{3}(x_2-x_1)\end{bmatrix} \end{align} $$ and $$ \begin{align} &\begin{bmatrix}x_1&y_1\end{bmatrix}+\begin{bmatrix}x_2-x_1&y_2-y_1\end{bmatrix}\begin{bmatrix}1/2&-\sqrt{3}/2\\\sqrt{3}/2&1/2\end{bmatrix}\\&=\frac{1}{2}\begin{bmatrix}(x_2+x_1)+\sqrt{3}(y_2-y_1)&(y_2+y_1)-\sqrt{3}(x_2-x_1)\end{bmatrix} \end{align} $$

share|improve this answer
    
nice! sorry but I forgot to put this answer as the right one. So, 2 things: 1) how have you generate the image of the two triangles? 2) What if I want to change the angle and do not an equilateral triangle but an isosceles? –  nkint Feb 11 at 9:32
    
@nkint: 1) I used Intaglio, which is a Mac-only graphics program, to generate the triangles. 2) Use $$M_+=\frac12\begin{bmatrix}1&\tan(\theta)\\-\tan(\theta)&1\end{bmatrix}$$ and $$M_-=\frac12\begin{bmatrix}1&-\tan(\theta)\\\tan(\theta)&1\end{bmatrix}$$ –  robjohn Feb 11 at 10:21

Since I feel that trigonometry is sooo underused in applications like this, here's an alternate method. But first, a diagram:

angles

Let's start with a line at an angle $\theta$ from the horizontal axis. From this, we want to find the slope of the line at an angle $\theta+\varphi$ from horizontal. This is easily obtained through the addition formula for the tangent:

$$\tan(\theta +\varphi )=\frac{\tan\,\theta+\tan\,\varphi}{1-\tan\,\theta \tan \,\varphi}$$

Now, let's use our example again. We know that $\tan\,\theta=\dfrac{27}{16}$. The point we need can be found by changing $\varphi$ accordingly; I'll show how to determine one of the possible points, and leave the other one as an exercise.

We can take the line passing through $(10,25)$ to have the slope $\tan(\theta-2\pi/3)$, and the line passing through $(42,79)$ to have the slope $\tan(\theta+2\pi/3)$. This results in the pair of lines

$$\begin{align*}y-25&=\frac{\frac{27}{16}-\tan\frac{2\pi}{3}}{1+\frac{27}{16}\tan\frac{2\pi}{3}}(x-10)\\y-79&=\frac{\frac{27}{16}+\tan\frac{2\pi}{3}}{1-\frac{27}{16}\tan\frac{2\pi}{3}}(x-42)\end{align*}$$

Finding the intersection of these two lines through the usual means yields the point $(26-27\sqrt3,52+16\sqrt3)$.

share|improve this answer

Say you have two points that are the ends of one side of the triangle, $P1=(P1.x,P1.y)$ and $P2=(P2.x,P2.y)$. The length of the side is $s=\sqrt{(P2.x-P1.x)^2+(P2.y-P1.y)^2}$ The midpoint of the side is $MP=(\frac{P1.x+P2.x}2,\frac{P1.y+P2.y}2)$. The slope of the segment from $P1$ to $P2$ is $m=\frac{P2.y-P1.y}{P2.x-P1.x}$, and the slope of the perpendicular (which will pass through the other vertex) is $-\frac1m$, which makes a unit vector $U=(\frac{\pm m}{1+m^2},\frac{\mp 1}{1+m^2})$. So you can use the point-slope form to find the third point. $P3=MP+Us$. There will be two solutions, one each side of the segment.

share|improve this answer
    
same comment as J.M. If i have P1(0,0) and P2(10,0) so m=0, and U=(0,1) and MP(5,5) and P3(5,6) or P3(5,4) that is wrong... –  nkint Dec 20 '11 at 9:54

I'll use your example of $(x_1,y_1)=(10,25)$ and $(x_2,y_2)=(42,79)$ to illustrate the idea. This is merely a reformulation of the answers given so far, but this might be a bit more convenient.

To get a few things we need out of the way, we compute the midpoint $(x_c,y_c)=(26,52)$, the segment length $d=2\sqrt{985}$, and the slope $m=\dfrac{27}{16}$.

The line perpendicular to our given segment has the slope $-\dfrac1{m}=-\dfrac{16}{27}$ and passes through $(x_c,y_c)$. A particularly convenient parametrization of this line is

$$\begin{align*}x&=x_c+\frac{mu}{\sqrt{1+m^2}}\\y&=y_c-\frac{u}{\sqrt{1+m^2}}\end{align*}$$

(See the stuff below the dividing line for a derivation.)

To get any of the two needed points we replace $u$ in the line parametrization with $u=\pm d\dfrac{\sqrt 3}{2}=\pm\sqrt{2955}$; this yields the points $(26\pm27\sqrt 3,52\mp16\sqrt 3)$.


Deriving a convenient parametrization for the line

Start with the usual point-slope form of the line:

$$y-y_1=m(x-x_1)$$

It is known that if the line makes an angle $\theta$ with respect to the horizontal axis, then $m=\tan\,\theta$. We can thus also consider the alternative form

$$\frac{y-y_1}{\sin\,\theta}=\frac{x-x_1}{\cos\,\theta}$$

Equate the two sides of this equation to a new parameter $u$, yielding

$$\begin{align*}x&=x_1+u\cos\,\theta\\y&=y_1+u\sin\,\theta\end{align*}$$

To remove $\theta$, we use the relation $\theta=\arctan\,u$, and express the cosine and sine entirely in terms of the tangent:

$$\begin{align*}\cos\,\theta&=\frac1{\sqrt{1+\tan^2 \theta}}\\\sin\,\theta&=\frac{\tan\,\theta}{\sqrt{1+\tan^2 \theta}}\end{align*}$$

This finally yields

$$\begin{align*}x&=x_1+\frac{u}{\sqrt{1+m^2}}\\y&=y_1+\frac{um}{\sqrt{1+m^2}}\end{align*}$$

The "convenient" part is due to the fact that $u$ can be interpreted as (signed) distance; that is, if $u=\pm h$, then the length of the segment joining the resulting point and $(x_1,y_1)$ is $h$. The sign determines any of the two directions one can proceed from the starting point.

A similar formula for the perpendicular is conveniently realized by replacing $m$ with $-\dfrac1{m}$.

share|improve this answer
1  
Really? I have $(x_c,y_c)=(5,0)$. Taking $m=0$ yields the parametrization $(5,-u)$. Before saying a formula is wrong, be absolutely sure the screw-up isn't from your end. –  J. M. Dec 20 '11 at 9:53
    
sorry but if the P1(0,0) and P2(10,0) and m=0 so P3.y=0 and this is wrong in this case.. –  nkint Dec 20 '11 at 9:56
    
@nkint: I'm using $$\begin{align*}x&=x_c+\frac{mu}{\sqrt{1+m^2}}\\y&=y_c-\frac{u}{\sqrt{1+m^2}}\end‌​{align*}$$ What formula are you using, and why do you insist that I'm wrong here? –  J. M. Dec 20 '11 at 10:03
    
Alright, let's work with that. You already have the midpoint $(5,0)$; take $m=0$ and $u=5\sqrt 3$, yielding $$\begin{align*}x&=5+\frac{0\times (5\sqrt 3)}{\sqrt{1+0^2}}=5\\y&=0-\frac{5\sqrt 3}{\sqrt{1+0^2}}=-5\sqrt 3\end{align*}$$. The other possible point is obtained by taking $u=-5\sqrt 3$. –  J. M. Dec 20 '11 at 10:37
    
sorry! it works perfectly! –  nkint Dec 20 '11 at 10:54

you can find the intersection of 2 circles:

both have a radius of $|P_1P_2|$ and the first circle has midpoint $P_1$ and the second circle has midpoint $P_2$

$$\begin{cases}(x-x_1)^2+(y-y_1)^2=|P_1P_2|^2 \\ (x-x_2)^2+(y-y_2)^2=|P_1P_2|^2 \end{cases}$$

$$\begin{cases}(x-x_1)^2+(y-y_1)^2=(x_2-x_1)^2+(y_2-y_1)^2 \\ (x-x_2)^2+(y-y_2)^2=(x_2-x_1)^2+(y_2-y_1)^2 \end{cases}$$

share|improve this answer

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.