如何find箭头提示点,给出一条线的起点和终点

考虑你有一个起点(x1,y1)和终点(x2,y2)的一条线。

为了在箭头上画一个箭头(在objective-c中),我需要find箭头(x3,y3,x4,y4)给定箭头的angular度(45度)的点,箭头提示(h)。

所以给定x1,y1,x2,y2,h,alpha什么是x3,y3,x4,y4?

添加了解释问题的图像。

如果答案可以在Objective-C(使用UIBezierpath和CGPoint),将不胜感激。

谢谢! 箭头绘图

#import <math.h> #import <UIKit/UIKit.h> #import <CoreGraphics/CoreGraphics.h> float phi = atan2(y2 - y1, x2 - x1); // substitute x1, x2, y1, y2 as needed float tip1angle = phi - M_PI / 4; // -45° float tip2angle = phi + M_PI / 4; // +45° float x3 = x2 - h * cos(tip1angle); // substitute h here and for the following 3 places float x4 = x2 - h * cos(tip2angle); float y3 = y2 - h * sin(tip1angle); float y4 = y2 - h * sin(tip2angle); CGPoint arrowStartPoint = CGPointMake(x1, y1); CGPoint arrowEndPoint = CGPointMake(x2, y2); CGPoint arrowTip1EndPoint = CGPointMake(x3, y3); CGPoint arrowTip2EndPoint = CGPointMake(x4, y4); CGContextRef ctx = UIGraphicsGetCurrentContext(); // assuming an UIView subclass [[UIColor redColor] set]; CGContextMoveToPoint(ctx, arrowStartPoint.x, arrowStartPoint.y); CGContextAddLineToPoint(ctx, arrowEndPoint.x, arrowEndPoint.y); CGContextAddLineToPoint(ctx, arrowTip1EndPoint.x, arrowTip1EndPoint.y); CGContextMoveToPoint(ctx, arrowEndPoint.x, arrowEndPoint.y); CGContextAddLineToPoint(ctx, arrowTip2EndPoint.x, arrowTip2EndPoint.y); 

我希望这有帮助 :)