Drawing triangle/arrow on a line with CGContext

前端 未结 4 1232
南笙
南笙 2021-02-01 09:06

I am using the framework of route-me for working with locations. In this code the path between two markers(points) will be drawn as a line.

My Question: \"What code shou

4条回答
  •  悲&欢浪女
    2021-02-01 09:49

    I found this question as I had the same. I took drawnonward's example and it was so close... But with a flipping of cos and sin, I was able to get it to work:

    r = atan2( ny - my , nx - mx );
    r += M_PI;
    bx = nx;
    by = ny;
    dx = bx + cos( r ) * length;
    dy = by + sin( r ) * length;
    r += M_PI_2; // perpendicular to path
    ax = dx + cos( r ) * width;
    ay = dy + sin( r ) * width;
    cx = dx - cos( r ) * width;
    cy = dy - sin( r ) * width;
    

    Once I did that, my arrows were pointed exactly the wrong way. So I added that second line (r += M_PI;)

    Thanks go to drawnonward!

提交回复
热议问题