绘制带箭头的直线
2011-08-14 23:10
218 查看
从vc移植到objective-c.感觉不错.分享之..
-(void)drawInContext:(CGContextRef)context{
CGContextSetRGBStrokeColor(context,1.0, 0.0,0.0, 1.0);
CGPoint m_One = CGPointMake(40.0,30.0);
CGPoint m_Two = CGPointMake(280.0,130.0);
double slopy , cosy , siny;
double Par =20.0; //length of Arrow (>)
slopy = atan2( ( m_One.y - m_Two.y ),
( m_One.x - m_Two.x ) );
cosy = cos( slopy );
siny = sin( slopy );//need math.h for these functions
CGContextMoveToPoint(context, m_Two.x, m_Two.y);
CGContextAddLineToPoint( context,m_Two.x + ( Par * cosy - ( Par /2.0 * siny ) ),
m_Two.y + ( Par * siny + ( Par /2.0 * cosy ) ) );
CGContextMoveToPoint( context,m_Two.x + ( Par * cosy + Par /2.0 * siny ),
m_Two.y - ( Par /2.0 * cosy - Par * siny ) );
CGContextAddLineToPoint(context, m_Two.x, m_Two.y);
CGContextSetLineWidth(context,2.0);
CGContextStrokePath(context);
}
-(void)drawInContext:(CGContextRef)context{
CGContextSetRGBStrokeColor(context,1.0, 0.0,0.0, 1.0);
CGPoint m_One = CGPointMake(40.0,30.0);
CGPoint m_Two = CGPointMake(280.0,130.0);
double slopy , cosy , siny;
double Par =20.0; //length of Arrow (>)
slopy = atan2( ( m_One.y - m_Two.y ),
( m_One.x - m_Two.x ) );
cosy = cos( slopy );
siny = sin( slopy );//need math.h for these functions
CGContextMoveToPoint(context, m_Two.x, m_Two.y);
CGContextAddLineToPoint( context,m_Two.x + ( Par * cosy - ( Par /2.0 * siny ) ),
m_Two.y + ( Par * siny + ( Par /2.0 * cosy ) ) );
CGContextMoveToPoint( context,m_Two.x + ( Par * cosy + Par /2.0 * siny ),
m_Two.y - ( Par /2.0 * cosy - Par * siny ) );
CGContextAddLineToPoint(context, m_Two.x, m_Two.y);
CGContextSetLineWidth(context,2.0);
CGContextStrokePath(context);
}
相关文章推荐
- Arcgis for js开发之直线、圆、箭头、多边形、集结地等绘制方法
- 绘制带箭头的直线
- 用OpenGL绘制带箭头的直线的代码
- MFC绘制坐标刻度和自定义线条以及带有箭头的直线
- MFC绘制坐标刻度和自定义线条以及带有箭头的直线
- Arcgis for js开发之直线、圆、箭头、多边形、集结地等绘制方法
- 绘制带箭头的直线
- iOS开发UI篇—Quartz2D简单图形绘制(二)直线,三角形,矩形,扇形,弧,圆
- 绘制余弦曲线和直线
- Delphi下的GDI+编程[3] 绘制直线-线帽
- Android 绘图(一)——绘制直线的drawnline方法
- AutoCAD LISP在直线中点绘制圆
- Qt的paint函数重写,以及QPaint给一条线绘制箭头
- matlab中绘制平行于坐标轴的直线
- html5教程 (二)(canvas绘制简单的直线)
- 绘制钻石图案。将一圆周进行n等分,然后将所有的等分用直线连接,构成图案。
- 利用matlab如何在图形中绘制箭头
- 【VC++】001绘制直线
- Highcharts绘制直线图
- IOS绘图API绘制直线几何图形