是不是这个效果
●/ ●—————>●
∧ / ∧
| / |
/ / /
/ / /
/ /->●
__________________________________________
摘自aizb大侠的代码
function GetDirection(FromLaOrLo, ToLaOrLo: TPoint): Double;
Var xDis,yDis
![Big Grin :D :D](https://cdn.jsdelivr.net/joypixels/assets/8.0/png/unicode/64/1f600.png)
OUBLE;//*0.00000001*180/3.1415926;
begin
xDis:=ToLaOrLo.x-FromLaOrLo.x;
//x方向的差值;
yDis:=ToLaOrLo.y-FromLaOrLo.y;
//y方向的差值;
if xDis<>0 then
Result:=ArcTan2(yDis,xDis)
else
begin
if ToLaOrLo.y-FromLaOrLo.y<0 then
Result:=pi*3/2
else
Result:=pi/2;
end;
end;
procedure proDrawDirection(Way: Single;cCanvas: TCanvas;R:LongInt;CentPoint:TPoint;DirectionStyle:TDirectionStyle;FromOrTo:Boolean;Color:TColor);
///////////////////////////////////////////////////////////////////////////////
//Way:Single,方向,即角度,弧度.
//cCanvas:TCanvas,画布,需要画箭头的画布.
//R:LongInt,箭头半径,即箭头的顶和脚三点形成的三解形的三个点所以圆的半径.
//CentPoint:TPoint,点,圆中心点.
//DirectionStyle:TDirectionStyle,绘制类型,
// dsFrame 画一个圆;
// dsShape 画箭头.
//FromOrTo:方向,正向or 反向.
//Color:TColor,绘制颜色.
///////////////////////////////////////////////////////////////////////////////
Var aPoint:TAPoint;
OldPenColor,OldBrushColor:TColor;
PenWidth:LongInt;
procedure GetPointList(CentPoint:TPoint;var PointList:Array of TPoint);
begin
PointList[0].x:=CentPoint.x;
PointList[0].y:=CentPoint.y;
PointList[1].x:=Round(CentPoint.x-R*2*COS(Way-pi/10)); //x
PointList[1].y:=Round(CentPoint.y-R*2*SIN(Way-pi/10)); //y
PointList[2].x:=Round(CentPoint.x-R*COS(Way)); //x
PointList[2].y:=Round(CentPoint.y-R*SIN(Way)); //y
PointList[3].x:=Round(CentPoint.x-R*2*COS(Way+pi/10)); //x
PointList[3].y:=Round(CentPoint.y-R*2*SIN(Way+pi/10)); //y
end;
begin
if (CentPoint.x=0) and (CentPoint.y=0) then
begin
CentPoint.x:=R;
CentPoint.y:=R;
end;
PenWidth:=cCanvas.Pen.Width;
OldPenColor:=cCanvas.Pen.Color;
OldBrushColor:=cCanvas.Brush.Color;
try
cCanvas.Pen.Width:=1;
if dsFrame in DirectionStyle then
begin
cCanvas.Pen.Color:=Color;
cCanvas.Brush.Color:=Color;
cCanvas.Ellipse(CentPoint.x-R,CentPoint.Y-R,CentPoint.x+R,CentPoint.y+R);
end;
if dsShape in DirectionStyle then
begin
SetLength(aPoint,4);
if FromOrTo then
GetPointList(CentPoint,aPoint)
else
begin
CentPoint.X:=Round(CentPoint.x+R*COS(Way));
CentPoint.Y:=Round(CentPoint.Y+R*Sin(Way));
GetPointList(CentPoint,aPoint);
end;
cCanvas.Pen.Color:=Color;
cCanvas.Brush.Color:=Color;
cCanvas.Polygon(aPoint);
end;
finally
cCanvas.Pen.Color:=OldPenColor;
cCanvas.Brush.Color:=OldBrushColor;
cCanvas.Pen.Width:=PenWidth;
end;
end;
调用:
proDrawDirection(GetDirection(Point(a.X,a.Y),a),Canvas,PR,a,[dsFrame],True,PenColor);