How I would do this is to find the slope of the line that is drawn between two points (start and end). The tilt will be (dy / dx) and this will be a good starting point for your arrow. Assuming you want the base of the arrow to be perpendicular to the line of the arrow, to find the tilt of the base, you will find the opposite back side of the tilt of the line. for example, let's say that your line has a slope of 2. The slope for the base of your triangle will be (-1/2), because you do (1 / (oldslope)) and multiply by -1. I don't know android very well, but if I remember correctly, in Java you would use the drawPolygon method, and you would need to specify 4 points (3 unique and 1 the same as the first to close it). Given the slope of the tip base, we can get our first two points and our end point. You must know before you start the dimensions of the arrow you want to draw, so in this case b will be the length of your baseline. If you take ϴ=arctan(dy/dx) , this will give you the angle between the x axis and the base level. With this value, you can do ydif = b*sin(ϴ) to get the difference in y value between the two base corners of the arrow. Doing the same, but with xdif = b*cos(ϴ) gives you the difference in the value of x between the two base points. If the location of the endpoint of the line drawn by the user is, say, (x1, y1) , then the locations of the base points of the triangle will be (x1-(xdif/2), y1-(ydif/2)) and (x1+(xdif/2), y1+(ydif/2)) . These two points, p1 and p2, are the first, second, and fourth points in the polygon drawing method. To find the third item, we need to find the angle of the original line by doing ϴ=arctan(dy/dx) , this time using your original dy / dx. with this angle. Before we finish the actual point calculation, you first need to know how far from the end of your line the arrowhead should be, in my case I will use var h and h = 10 . To get the coordinate, (x, y), assuming the cord for the tip of the line is (x1, y1), you would do (x1+hcosϴ, y1+hsinϴ) . Use this for the third value in drawPolygon() , and you need to do this. Sorry, if I rushed at the end, I’m tired of typing, commenting, if you need help.
source share