一些关于点的函数
点击次数:49 次 发布日期:2008-11-09 08:40:55 作者:源代码网
|
源代码网推荐 源代码网推荐 interface 源代码网推荐 源代码网推荐 uses 源代码网推荐 WinTypes, Classes, Graphics, SysUtils; 源代码网推荐 源代码网推荐 type 源代码网推荐 TPoint2D = record 源代码网推荐 X, Y: Real; 源代码网推荐 end; 源代码网推荐 TPoint3D = record 源代码网推荐 X, Y, Z: Real; 源代码网推荐 end; 源代码网推荐 源代码网推荐 function Point2D(X, Y: Real): TPoint2D; 源代码网推荐 function RoundPoint(P: TPoint2D): TPoint; 源代码网推荐 function FloatPoint(P: TPoint): TPoint2D; 源代码网推荐 function Point3D(X, Y, Z: Real): TPoint3D; 源代码网推荐 function Angle2D(P: TPoint2D): Real; 源代码网推荐 function Dist2D(P: TPoint2D): Real; 源代码网推荐 function Dist3D(P: TPoint3D): Real; 源代码网推荐 function RelAngle2D(PA, PB: TPoint2D): Real; 源代码网推荐 function RelDist2D(PA, PB: TPoint2D): Real; 源代码网推荐 function RelDist3D(PA, PB: TPoint3D): Real; 源代码网推荐 procedure Rotate2D(var P: TPoint2D; Angle2D: Real); 源代码网推荐 procedure RelRotate2D(var P: TPoint2D; PCentr: TPoint2D; Angle2D: Real); 源代码网推荐 procedure Move2D(var P: TPoint2D; Angle2D, Distance: Real); 源代码网推荐 function Between(PA, PB: TPoint2D; Preference: Real): TPoint2D; 源代码网推荐 function DistLine(A, B, C: Real; P: TPoint2D): Real; 源代码网推荐 function Dist2P(P, P1, P2: TPoint2D): Real; 源代码网推荐 function DistD1P(DX, DY: Real; P1, P: TPoint2D): Real; 源代码网推荐 function NearLine2P(P, P1, P2: TPoint2D; D: Real): Boolean; 源代码网推荐 function AddPoints(P1, P2: TPoint2D): TPoint2D; 源代码网推荐 function SubPoints(P1, P2: TPoint2D): TPoint2D; 源代码网推荐 源代码网推荐 function Invert(Col: TColor): TColor; 源代码网推荐 function Dark(Col: TColor; Percentage: Byte): TColor; 源代码网推荐 function Light(Col: TColor; Percentage: Byte): TColor; 源代码网推荐 function Mix(Col1, Col2: TColor; Percentage: Byte): TColor; 源代码网推荐 function MMix(Cols: array of TColor): TColor; 源代码网推荐 function Log(Base, Value: Real): Real; 源代码网推荐 function Modulator(Val, Max: Real): Real; 源代码网推荐 function M(I, J: Integer): Integer; 源代码网推荐 function Tan(Angle2D: Real): Real; 源代码网推荐 procedure Limit(var Value: Integer; Min, Max: Integer); 源代码网推荐 function Exp2(Exponent: Byte): Word; 源代码网推荐 function GetSysDir: String; 源代码网推荐 function GetWinDir: String; 源代码网推荐 源代码网推荐 implementation 源代码网推荐 源代码网推荐 function Point2D(X, Y: Real): TPoint2D; 源代码网推荐 begin 源代码网推荐 Point2D.X := X; 源代码网推荐 Point2D.Y := Y; 源代码网推荐 end; 源代码网推荐 源代码网推荐 function RoundPoint(P: TPoint2D): TPoint; 源代码网推荐 begin 源代码网推荐 RoundPoint.X := Round(P.X); 源代码网推荐 RoundPoint.Y := Round(P.Y); 源代码网推荐 end; 源代码网推荐 源代码网推荐 function FloatPoint(P: TPoint): TPoint2D; 源代码网推荐 begin 源代码网推荐 FloatPoint.X := P.X; 源代码网推荐 FloatPoint.Y := P.Y; 源代码网推荐 end; 源代码网推荐 源代码网推荐 function Point3D(X, Y, Z: Real): TPoint3D; 源代码网推荐 begin 源代码网推荐 Point3D.X := X; 源代码网推荐 Point3D.Y := Y; 源代码网推荐 Point3D.Z := Z; 源代码网推荐 end; 源代码网推荐 源代码网推荐 function Angle2D(P: TPoint2D): Real; 源代码网推荐 begin 源代码网推荐 if P.X = 0 then 源代码网推荐 begin 源代码网推荐 if P.Y > 0 then Result := Pi / 2; 源代码网推荐 if P.Y = 0 then Result := 0; 源代码网推荐 if P.Y < 0 then Result := Pi / -2; 源代码网推荐 end 源代码网推荐 else 源代码网推荐 Result := Arctan(P.Y / P.X); 源代码网推荐 源代码网推荐 if P.X < 0 then 源代码网推荐 begin 源代码网推荐 if P.Y < 0 then Result := Result Pi; 源代码网推荐 if P.Y >= 0 then Result := Result - Pi; 源代码网推荐 end; 源代码网推荐 源代码网推荐 If Result < 0 then Result := Result 2 * Pi; 源代码网推荐 end; 源代码网推荐 源代码网推荐 function Dist2D(P: TPoint2D): Real; 源代码网推荐 begin 源代码网推荐 Result := Sqrt(P.X * P.X P.Y * P.Y); 源代码网推荐 end; 源代码网推荐 源代码网推荐 function Dist3D(P: TPoint3D): Real; 源代码网推荐 begin 源代码网推荐 Dist3d := Sqrt(P.X * P.X P.Y * P.Y P.Z * P.Z); 源代码网推荐 end; 源代码网推荐 源代码网推荐 function RelAngle2D(PA, PB: TPoint2D): Real; 源代码网推荐 begin 源代码网推荐 RelAngle2D := Angle2D(Point2D(PB.X - PA.X, PB.Y - PA.Y)); 源代码网推荐 end; 源代码网推荐 源代码网推荐 function RelDist2D(PA, PB: TPoint2D): Real; 源代码网推荐 begin 源代码网推荐 Result := Dist2D(Point2D(PB.X - PA.X, PB.Y - PA.Y)); 源代码网推荐 end; 源代码网推荐 源代码网推荐 function RelDist3D(PA, PB: TPoint3D): Real; 源代码网推荐 begin 源代码网推荐 RelDist3D := Dist3D(Point3D(PB.X - PA.X, PB.Y - PA.Y, PB.Z - PA.Z)); 源代码网推荐 end; 源代码网推荐 源代码网推荐 procedure Rotate2D(var P: TPoint2D; Angle2D: Real); 源代码网推荐 var 源代码网推荐 Temp: TPoint2D; 源代码网推荐 begin 源代码网推荐 Temp.X := P.X * Cos(Angle2D) - P.Y * Sin(Angle2D); 源代码网推荐 Temp.Y := P.X * Sin(Angle2D) P.Y * Cos(Angle2D); 源代码网推荐 P := Temp; 源代码网推荐 end; 源代码网推荐 源代码网推荐 procedure RelRotate2D(var P: TPoint2D; PCentr: TPoint2D; Angle2D: Real); 源代码网推荐 var 源代码网推荐 Temp: TPoint2D; 源代码网推荐 begin 源代码网推荐 Temp := SubPoints(P, PCentr); 源代码网推荐 Rotate2D(Temp, Angle2D); 源代码网推荐 P := AddPoints(Temp, PCentr); 源代码网推荐 end; 源代码网推荐 源代码网推荐 procedure Move2D(var P: TPoint2D; Angle2D, Distance: Real); 软件开发网 www.mscto.com 源代码网推荐 var 源代码网推荐 Temp: TPoint2D; 源代码网推荐 begin 源代码网推荐 Temp.X := P.X (Cos(Angle2D) * Distance); 源代码网推荐 Temp.Y := P.Y (Sin(Angle2D) * Distance); 源代码网推荐 P := Temp; 源代码网推荐 end; 源代码网推荐 源代码网推荐 function Between(PA, PB: TPoint2D; Preference: Real): TPoint2D; 源代码网推荐 begin 源代码网推荐 Between.X := PA.X * Preference PB.X * (1 - Preference); 源代码网推荐 Between.Y := PA.Y * Preference PB.Y * (1 - Preference); 源代码网推荐 end; 源代码网推荐 源代码网推荐 function DistLine(A, B, C: Real; P: TPoint2D): Real; 源代码网推荐 begin 源代码网推荐 Result := (A * P.X B * P.Y C) / Sqrt(Sqr(A) Sqr(B)); 源代码网推荐 end; 源代码网推荐 源代码网推荐 function Dist2P(P, P1, P2: TPoint2D): Real; 源代码网推荐 begin 源代码网推荐 Result := DistLine(P1.Y - P2.Y, P2.X - P1.X, -P1.Y * P2.X P1.X * P2.Y, P); 源代码网推荐 end; 源代码网推荐 源代码网推荐 function DistD1P(DX, DY: Real; P1, P: TPoint2D): Real; 源代码网推荐 begin 源代码网推荐 Result := DistLine(DY, -DX, -DY * P1.X DX * P1.Y, P); 源代码网推荐 end; 源代码网推荐 源代码网推荐 function NearLine2P(P, P1, P2: TPoint2D; D: Real): Boolean; 源代码网推荐 begin 源代码网推荐 Result := False; 源代码网推荐 if DistD1P(-(P2.Y - P1.Y), P2.X - P1.X, P1, P) * DistD1P(-(P2.Y - P1.Y), P2.X - P1.X, P2, P) <= 0 then 源代码网推荐 if Abs(Dist2P(P, P1, P2)) < D then Result := True; 源代码网推荐 end; 源代码网推荐 源代码网推荐 function AddPoints(P1, P2: TPoint2D): TPoint2D; 源代码网推荐 begin 源代码网推荐 AddPoints := Point2D(P1.X P2.X, P1.Y P2.Y); 源代码网推荐 end; 源代码网推荐 源代码网推荐 function SubPoints(P1, P2: TPoint2D): TPoint2D; 源代码网推荐 begin 源代码网推荐 SubPoints := Point2D(P1.X - P2.X, P1.Y - P2.Y); 源代码网推荐 end; 源代码网推荐 源代码网推荐 function Invert(Col: TColor): TColor; 源代码网推荐 begin 源代码网推荐 Invert := not Col; 源代码网推荐 end; 源代码网推荐 源代码网推荐 function Dark(Col: TColor; Percentage: Byte): TColor; 源代码网推荐 var 源代码网推荐 R, G, B: Byte; 源代码网推荐 begin 源代码网推荐 R := GetRValue(Col); G := GetGValue(Col); B := GetBValue(Col); 源代码网推荐 R := Round(R * Percentage / 100); 源代码网推荐 G := Round(G * Percentage / 100); 源代码网推荐 B := Round(B * Percentage / 100); 源代码网推荐 Dark := RGB(R, G, B); 源代码网推荐 end; 源代码网推荐 源代码网推荐 function Light(Col: TColor; Percentage: Byte): TColor; 源代码网推荐 var 源代码网推荐 R, G, B: Byte; 源代码网推荐 begin 源代码网推荐 R := GetRValue(Col); G := GetGValue(Col); B := GetBValue(Col); 源代码网推荐 R := Round(R * Percentage / 100) Round(255 - Percentage / 100 * 255); 源代码网推荐 G := Round(G * Percentage / 100) Round(255 - Percentage / 100 * 255); 源代码网推荐 B := Round(B * Percentage / 100) Round(255 - Percentage / 100 * 255); 源代码网推荐 Light := RGB(R, G, B); 源代码网推荐 end; 源代码网推荐 源代码网推荐 function Mix(Col1, Col2: TColor; Percentage: Byte): TColor; 源代码网推荐 var 源代码网推荐 R, G, B: Byte; 源代码网推荐 begin 源代码网推荐 R := Round((GetRValue(Col1) * Percentage / 100) (GetRValue(Col2) * (100 - Percentage) / 100)); 源代码网推荐 G := Round((GetGValue(Col1) * Percentage / 100) (GetGValue(Col2) * (100 - Percentage) / 100)); 源代码网推荐 B := Round((GetBValue(Col1) * Percentage / 100) (GetBValue(Col2) * (100 - Percentage) / 100)); 源代码网推荐 Mix := RGB(R, G, B); 源代码网推荐 end; 源代码网推荐 源代码网推荐 function MMix(Cols: array of TColor): TColor; 源代码网推荐 var 源代码网推荐 I, R, G, B, Length: Integer; 源代码网推荐 begin 源代码网推荐 Length := High(Cols) - Low(Cols) 1; 源代码网推荐 R := 0; G := 0; B := 0; 源代码网推荐 for I := Low(Cols) to High(Cols) do 源代码网推荐 begin 源代码网推荐 R := R GetRValue(Cols[I]); 源代码网推荐 G := G GetGValue(Cols[I]); 源代码网推荐 B := B GetBValue(Cols[I]); 源代码网推荐 end; 源代码网推荐 R := R div Length; 源代码网推荐 G := G div Length; 源代码网推荐 B := B div Length; 源代码网推荐 MMix := RGB(R, G, B); 源代码网推荐 end; 源代码网推荐 源代码网推荐 function Log(Base, Value: Real): Real; 源代码网推荐 begin 源代码网推荐 Log := Ln(Value) / Ln(Base); 源代码网推荐 end; 源代码网推荐 源代码网推荐 function Power(Base, Exponent: Real): Real; 源代码网推荐 begin 源代码网推荐 Power := Ln(Base) * Exp(Exponent); 源代码网推荐 end; 源代码网推荐 源代码网推荐 function Modulator(Val, Max: Real): Real; 源代码网推荐 begin 源代码网推荐 Modulator := (Val / Max - Round(Val / Max)) * Max; 源代码网推荐 end; 源代码网推荐 源代码网推荐 function M(I, J: Integer): Integer; 源代码网推荐 begin 源代码网推荐 M := ((I mod J) J) mod J; 源代码网推荐 end; 源代码网推荐 源代码网推荐 function Tan(Angle2D: Real): Real; 源代码网推荐 begin 源代码网推荐 Tan := Sin(Angle2D) / Cos(Angle2D); 源代码网推荐 end; 源代码网推荐 源代码网推荐 procedure Limit(var Value: Integer; Min, Max: Integer); 源代码网推荐 begin 源代码网推荐 if Value < Min then Value := Min; 源代码网推荐 if Value > Max then Value := Max; 源代码网推荐 end; 源代码网推荐 源代码网推荐 function Exp2(Exponent: Byte): Word; 源代码网推荐 var 源代码网推荐 Temp, I: Word; 源代码网推荐 begin 源代码网推荐 Temp := 1; 源代码网推荐 for I := 1 to Exponent do 源代码网推荐 Temp := Temp * 2; 源代码网推荐 Result := Temp; 源代码网推荐 end; 源代码网推荐 源代码网推荐 function GetSysDir: String; 源代码网推荐 var 源代码网推荐 Temp: array[0..255] of Char; 源代码网推荐 begin 源代码网推荐 GetSystemDirectory(Temp, 256); 源代码网推荐 Result := StrPas(Temp); 源代码网推荐 end; 源代码网推荐 源代码网推荐 function GetWinDir: String; 源代码网推荐 var 源代码网推荐 Temp: array[0..255] of Char; 源代码网推荐 begin 源代码网推荐 GetWindowsDirectory(Temp, 256); 源代码网推荐 Result := StrPas(Temp); 源代码网推荐 end; 源代码网推荐 源代码网推荐 end. 源代码网推荐 源代码网供稿. |
