1
$\begingroup$

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.

  • 3
    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.)?2011-06-07
  • 0
    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.2011-06-07
  • 0
    ... The coordinates depend solely on the size of the triangle... so be more specific...2011-06-07
  • 0
    @Nicolas. Let's say I need a triangle of 2cm of each sides. Could you propose me any formula for that please?2011-06-07

1 Answers 1

2

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?

  • 0
    But I don't know the angle of my line, I have only two pairs of coordinates corresponding to two sides of my line.2011-06-07
  • 1
    @Bakhtiyor: Do you know how to find the slope $m$ of the line? The angle $\theta$ is such that $\tan \theta=m$.2011-06-07
  • 1
    The slope $m=\frac{y_2-y_1}{x_2-x_1}$2011-06-07
  • 0
    Thanks @Ross and @Américo. Let me try and see what will happen...2011-06-07
  • 0
    $(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.2011-06-07
  • 0
    @Ross. I have solved the problem. Thanks a lot.2011-06-07