当前位置:编程学习 > Delphi >>

delphi ,函数完善。200分。详细需求已经给出。11111111111111

Function TForm1.GetNear(Const Point: TPoint; // 指定的点 Const InPoints: Array Of TPoint; // 知道的点 Var OutPoints: Array Of TPoint; // 返回的结果的垫 Radius: Double // 寻找的半径 ,-1标示仅仅最近的,是在Point和该点连线的45度范围内。 ): Integer; // 返回的点数 Function DistinceTwoPoint(P1, P2: TPoint): Double; Begin Result := Sqrt(Sqr(P1.X - P2.X) + (P1.Y - P2.Y)); End; Function AngleTwoPoint(P, P1, P2: TPoint): Double; Var Angle1, Angle2: Double; Begin Angle1 :=; Angle2 :=; Result := Abs(Angle2 - Angle1); End; Var I: Integer; Distince: Array Of Double; Angle: Array Of Double; Begin SetLength(Distince, Length(InPoints)); For I := Low(InPoints) To High(InPoints) Do Begin Distince[I] := DistinceTwoPoint(Point, InPoints[I]); End; Result := Length(OutPoints); End;
追问:你好,首先谢谢你的回答,我要的是如何完善,不是不知道需要注释。

好坏我从04年就开始学D了。虽然D现在用的人少。

我始终坚信,腿不行,就不要怪路不平。
答案:详细需求在哪呢?
"寻找的半径 ,-1标示仅仅最近的,是在Point和该点连线的45度范围内。"是指搜索原点指向Point点的向量的,以Point点为顶角正负45度范围内的点吗?

Function TForm1.GetNear(Const Point: TPoint; // 指定的点
 Const InPoints: Array Of TPoint; // 知道的点
 Var OutPoints: Array Of TPoint; // 返回的结果的垫
 Radius: Double // 寻找的半径 ,-1标示仅仅最近的,是在Point和该点连线的45度范围内。
 ): Integer; // 返回的点数

Function DistinceTwoPoint(P1, P2: TPoint): Double;
 Begin
  Result := Sqrt(Sqr(P1.X - P2.X) + Sqr(P1.Y - P2.Y));
 End;

 Function AngleTwoPoint(P, P1, P2: TPoint): Double;
 Var
  Angle1, Angle2: Double;
 Begin
  Angle1 := 3.1415926 * ArcTan2((P1.Y-P.Y),(P1.X-P.X)); //p1和p的角度
  Angle2 := 3.1415926 * ArcTan2((P2.Y-P.Y),(P2.X-P.X)); //p2和p的角度
  Result := Abs(Angle2 - Angle1);
 End;

Var
 I: Integer;
 Distince: Array Of Double;
 Angle: Array Of Double;
Begin
 SetLength(Distince, Length(InPoints)); //设置数组Distince的长度
 For I := Low(InPoints) To High(InPoints) Do
 Begin
  Distince[I] := DistinceTwoPoint(Point, InPoints[I]); //计算每个点和p的距离
 End;
//根据传入的半径
if (radius > 0) then
begin
//先清空输出数组
//然后判断每个点的距离是否合法,合法的点添加到outpoints
end
else if (radius = -1) then
begin
//循环各点,获取最小距离的那个,在判断最小距离时,根据需求进行角度判断
end;
 Result := Length(OutPoints); //返回OutPoints的个数
End;
其他:unit表示单元名称
interface表示你这个单元要留出来的接口,一般用做声明全局。
uses表示要引用的单文。
你如果去继承TObject那你的工作量是可想而知的。祝你好运。

像你要的,应该是一个公用的单元文件。你在文件——新建——Unit
unit Unit1;

interface

implementation

end.
这是自动成生的代码。如按你所说的,应该这样改
unit Unit2;

interface
uses
  //你要引用的单元写在这里

type
  TMyClass = class(TObject)
  private
    
    //私有字段,属性
  public
    
    //公有字段,属性
  end;
var
  MyClass:TMyClass;
implementation
//如果在interface的Type部分有函数或过程,应在这里写出他的内部!
end.
 

上一个:delphi 2010 运行时有道词典屏幕取词,Access violation at address 50065924 in module 'rtl140.bpl'报错
下一个:delphi中,我想按字母a,触发一个事件,怎么写?

CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,