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.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm not a mathematician, so please be patient!

I need formulas to calculate the two intersection points of a triangle and a square which are configured as shown in my image below.



The right-isosceles triangle and the square have fixed sizes. The triangle has both side lengths = $t$. The square has side lengths = $s$.

The triangle is always un-rotated and fixed at the origin $(0,0)$.

The square is rotated around it's center point $(x_3,y_3)$ by $r$ degrees.

The square will only move and rotate very, very slightly from the position below.

The intersection will always involve the triangle's hypotenuse and the same two sides of the square shown below.

I hope to use your solution to calculate $(x_1,y_1)$ and $(x_2,y_2)$ for various positions and rotations of the square.

Thank you in advance for your help and feel free to ask for more info if needed…

share|cite|improve this question
As you already know which lines of the shapes will intersect, this boils down to writing down the equations of these lines, preferrably in normal form $ax+by=c$, and then solving two systems of two linear equations each. At least in the most direct aproach. – MvG Jan 9 '13 at 8:20
up vote 0 down vote accepted

The hypothenuse of the triangle has the equation

$$ x + y = t $$

The direction of the square which is “right” in case of $r=0$ has the following normal (i.e. direction orthogonal to the line):

$$ \begin{pmatrix} \cos r \\ \sin r \end{pmatrix} $$

As the coefficients in the equation of a line are proportional to the normal, the left side of the square will be an equation of the form

$$ \cos r \cdot x + \sin r \cdot y = c $$

for some parameter $c$. You also know that when you start at the center and move a length $s$ in the opposite direction of that normal vector, you end up at the center of the left side. You can plug that into the equation to obtain $c$:

$$ c = \cos r \cdot (x_3 - s\cos r) + \sin r \cdot (y_3 -s\sin r) = x_3\cos r + y_3\sin r - s $$

So the equation of the left side of the square is

$$ \cos r \cdot x + \sin r \cdot y = x_3\cos r + y_3\sin r - s $$

Take these two equations together to compute $(x_1, y_1)$:

\begin{align*} x_1 + y_1 &= t \\ \cos r \cdot x_1 + \sin r \cdot y_1 &= x_3\cos r + y_3\sin r - s \end{align*}

Repeat the above computations with the “up” direction instead of the “right” direction in order to obtain $(x_2,y_2)$. The “up” vector is

$$ \begin{pmatrix} -\sin r \\ \cos r \end{pmatrix} $$

share|cite|improve this answer
Thank you, MvG! This was the help that I needed. – markE Jan 9 '13 at 14:06

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.