如何計算兩點長度 |
尚未結案
|
bd123777
一般會員 ![]() ![]() 發表:1 回覆:1 積分:0 註冊:2009-08-13 發送簡訊給我 |
|
小傑克
資深會員 ![]() ![]() ![]() ![]() ![]() 發表:5 回覆:209 積分:357 註冊:2009-02-16 發送簡訊給我 |
|
hagar
版主 ![]() ![]() ![]() ![]() ![]() ![]() 發表:143 回覆:4056 積分:4445 註冊:2002-04-14 發送簡訊給我 |
補充:
1.求兩點間距離: http://music.kh.edu.tw/project/pythagras/apply.htm 2.Pixels 轉成 Millimeters http://delphi.about.com/od/adptips2005/qt/pixel2mm.htm |
bd123777
一般會員 ![]() ![]() 發表:1 回覆:1 積分:0 註冊:2009-08-13 發送簡訊給我 |
我把我的code貼上來
unit Unit1; interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ExtCtrls; type TForm1 = class(TForm) Image1: TImage; Button1: TButton; procedure Image1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.DFM} procedure TForm1.Image1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); begin image1.Picture:=nil; image1.canvas.pen.Color := clred; image1.Canvas.pen.Width := 1; image1.canvas.Ellipse(x 10,y 10,x-10,y-10); //到這裡我就不會了... end; end. //這樣程式執行後可出現圓圈,但我想在點完一個圓圈後,在點第二個圓圈,然後形成一條線,並顯示出長度....... |
小傑克
資深會員 ![]() ![]() ![]() ![]() ![]() 發表:5 回覆:209 積分:357 註冊:2009-02-16 發送簡訊給我 |
參考hagar 大提供的function, 我直接畫在form 上面
unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs,Math; type TForm1 = class(TForm) procedure FormMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); procedure FormCreate(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; OldX,OldY:integer; implementation {$R *.dfm} procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); var iPixels:integer; rLen:real; begin canvas.pen.Color := clred; Canvas.pen.Width := 1; canvas.Ellipse(x 10,y 10,x-10,y-10); if OldX <> 0 then begin iPixels := Round( Power( Power(ABS(OldX-X),2) Power(ABS(OldY-Y),2) , 0.5 )) ; rLen := iPixels / ( PixelsPerInch / 2.54 ); Caption := FloattoStr( RoundTo( rLen, -1 ) ); end; OldX := X; OldY := Y; end; procedure TForm1.FormCreate(Sender: TObject); begin OldX := 0; OldY := 0; end; end.
------
額有朝天骨,眼中有靈光 |
hagar
版主 ![]() ![]() ![]() ![]() ![]() ![]() 發表:143 回覆:4056 積分:4445 註冊:2002-04-14 發送簡訊給我 |
// 畫線部份
unit Unit3; interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, Math, StdCtrls; type TForm1 = class(TForm) procedure FormMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); procedure FormMouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); private FX1, FY1: integer; FX2, FY2: integer; public { Public declarations } end; var Form1: TForm1; implementation {$R *.DFM} procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); begin Self.Canvas.Pen.Color := clBlue; Self.Canvas.MoveTo(X, Y); FX1 := X; FY1 := Y; end; procedure TForm1.FormMouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); var a,b: integer; c: Extended; inch: Extended; xmm, ymm: Extended; begin Self.Canvas.LineTo(X, Y); FX2 := X; FY2 := Y; a := Abs(FX1 - FX2); b := Abs(FY1 - FY2); c := Sqrt(Power(a, 2) Power(b, 2)); // 算長度 end; end.
編輯記錄
hagar 重新編輯於 2009-08-13 16:34:45, 註解 無‧
|
Ktop_Robot
站務副站長 ![]() ![]() 發表:0 回覆:3511 積分:0 註冊:2007-04-17 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |