Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. Join them; it only takes a minute:

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 need to draw a triangle like an arrow in the middle of the line. How can I calculate triangle's coordinates in order to draw it in the middle of the line PLEASE?

enter image description here

** UPDATE **

Here I have found out how to find the middle of the line, so now I have a coordinate for one of three vertices of the triangle. I need to calculate coordinates of other two vertices.

share|cite|improve this question
How big do you want the triangle to be? Do you want the tip of the Triangle to be exactly half way? Do you want the 'center' of the triangle to be half way? If so, which center (centroid, circumcenter, etc.)? – Nicolas Villanueva Jun 7 '11 at 15:43
Generally it is not so important for me. I need to locate a triangle like an arrow in the middle of the line more or less. The size of the triangle is enough to be like in the figure above. – Bakhtiyor Jun 7 '11 at 15:47
... The coordinates depend solely on the size of the triangle... so be more specific... – Nicolas Villanueva Jun 7 '11 at 15:55
@Nicolas. Let's say I need a triangle of 2cm of each sides. Could you propose me any formula for that please? – Bakhtiyor Jun 7 '11 at 15:59
up vote 2 down vote accepted

First start with a triangle of the size you want, say directed to the right. The three corners are then $(0,0), (x_0,y_0), (x_0,-y_0)$ where $x_0 \lt 0$. You just multiply these by the rotation matrix $$\left(\begin {array}{c c}\cos \theta & \sin \theta \\ -\sin \theta & \cos \theta \end{array}\right)\left(\begin {array}{c}x_0 \\ y_0 \end{array}\right)$$ to get each point relative to the head of your arrow. To get $\theta$ you need the angle of your line. How is that represented?

share|cite|improve this answer
But I don't know the angle of my line, I have only two pairs of coordinates corresponding to two sides of my line. – Bakhtiyor Jun 7 '11 at 16:05
@Bakhtiyor: Do you know how to find the slope $m$ of the line? The angle $\theta$ is such that $\tan \theta=m$. – Américo Tavares Jun 7 '11 at 16:20
The slope $m=\frac{y_2-y_1}{x_2-x_1}$ – Ross Millikan Jun 7 '11 at 16:22
Thanks @Ross and @Américo. Let me try and see what will happen... – Bakhtiyor Jun 7 '11 at 16:28
$(x_0,y_0)$ sets the size of your triangle. It looks like something about $(x_2-x_1)/20$ is about right-I don't know the scale of your figure. These are offsets from your xx1, so xx2=xx1+Math.cos(alfa)*x0+Math.sin(alfa)*y0 and similar for xx3, yy2, yy3. – Ross Millikan Jun 7 '11 at 18:17

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.