線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:1473
推到 Plurk!
推到 Facebook!

任意一條直線切等分算座標?

答題得分者是:diablo09105
a58705077
一般會員


發表:2
回覆:1
積分:0
註冊:2008-11-13

發送簡訊給我
#1 引用回覆 回覆 發表時間:2011-07-30 15:29:57 IP:112.105.xxx.xxx 訂閱
各位先進,有一個問題困惱著我寫程式

我有一條直線,有起始點(x1,y1)跟終點座標(x2,y2),現在我要把這條直線切成十等份,並算出十等份上所有的座標.

我目前作法是(x1 x2)*(1/10) x1
(y1 y2)*(1/10) y1

但是座標不會再直線上,請教各位先進,有什麼辦法可以讓切十等份且座標都在線上.

謝謝
diablo09105
一般會員


發表:25
回覆:45
積分:24
註冊:2011-05-31

發送簡訊給我
#2 引用回覆 回覆 發表時間:2011-07-31 00:40:28 IP:118.167.xxx.xxx 訂閱
我的程式沒有使用小數點
如果需要請自行修改喔~~~
請參考↓↓↓


[code cpp]
//---------------------------------------------------------------------------
#include
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 * Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent * Owner): TForm(Owner){}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormMouseDown(TObject * Sender, TMouseButton Button, TShiftState Shift, int X, int Y)
{
if (Button == mbLeft)
{
Canvas->MoveTo(X, Y);
Canvas->LineTo(X, Y);
edt1->Text = X;
edt2->Text = Y;
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormMouseUp(TObject * Sender, TMouseButton Button, TShiftState Shift, int X, int Y)
{
int abc, def;
if (Button == mbLeft)
{
Canvas->LineTo(X, Y);

edt3->Text = X;
edt4->Text = Y;

abc = ((edt3->Text) - (edt1->Text)) / 10;
def = ((edt4->Text) - (edt2->Text)) / 10;

edt5->Text = abc StrToInt(edt1->Text);
edt7->Text = abc * 2 StrToInt(edt1->Text);
edt9->Text = abc * 3 StrToInt(edt1->Text);
edt11->Text = abc * 4 StrToInt(edt1->Text);
edt13->Text = abc * 5 StrToInt(edt1->Text);
edt15->Text = abc * 6 StrToInt(edt1->Text);
edt17->Text = abc * 7 StrToInt(edt1->Text);
edt19->Text = abc * 8 StrToInt(edt1->Text);
edt21->Text = abc * 9 StrToInt(edt1->Text);
edt23->Text = abc * 10 StrToInt(edt1->Text);

edt6->Text = def StrToInt(edt2->Text);
edt8->Text = def * 2 StrToInt(edt2->Text);
edt10->Text = def * 3 StrToInt(edt2->Text);
edt12->Text = def * 4 StrToInt(edt2->Text);
edt14->Text = def * 5 StrToInt(edt2->Text);
edt16->Text = def * 6 StrToInt(edt2->Text);
edt18->Text = def * 7 StrToInt(edt2->Text);
edt20->Text = def * 8 StrToInt(edt2->Text);
edt22->Text = def * 9 StrToInt(edt2->Text);
edt24->Text = def * 10 StrToInt(edt2->Text);
}
}
//---------------------------------------------------------------------------
[/code]

------
燒毛崴
系統時間:2024-04-27 6:04:49
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!