ページ 11

テストが近づいてきてるので・・・

Posted: 2014年7月08日(火) 18:21
by ドウビエン
テストでは一行一行説明できればテストは万全らしいので。
ぜひ訳(意味)を教えてください
正直あんま理解せずに授業を受けてきたのでお手柔らかに
お願いします。。。

#include"math.h"
#define pi 3.14
void Ctest1Dlg::OnBnClickedButton1()
{
// TODO: ここにコントロール通知ハンドラー コードを追加します。

CWnd*h=GetDlgItem(IDC_PICTURE);
CDC*pDC=h->GetDC();
CRect r;
h->GetClientRect(&r);
pDC->FillSolidRect(r, RGB(255, 255, 255));

CString CentX, CentY, A, B, BETA;
int centx, centy, a, b, i, x, y, xx, yy;
double rd=pi/180, beta;

CEdit* x00=(CEdit*)GetDlgItem(IDC_EDIT1);
CEdit* y00=(CEdit*)GetDlgItem(IDC_EDIT2);
CEdit* a00=(CEdit*)GetDlgItem(IDC_EDIT3);
CEdit* b00=(CEdit*)GetDlgItem(IDC_EDIT4);
CEdit* beta00=(CEdit*)GetDlgItem(IDC_EDIT5);

x00->GetWindowTextW(CentX);
y00->GetWindowTextW(CentY);
a00->GetWindowTextW(A);
b00->GetWindowTextW(B);
beta00->GetWindowTextW(BETA);

centx=_ttoi(CentX);
centy=_ttoi(CentY);
a=_ttoi(A);
b=_ttoi(B);
beta=_ttof(BETA);

for(i=0; i<360; i++){
x=int(a*cos(i*rd));
y=int(b*sin(i*rd));

xx=centx+int(x*cos(beta*rd)-y*sin(beta*rd));
yy=centy+int(x*sin(beta*rd)+y*cos(beta*rd));

if(i==0)
pDC->MoveTo(xx, yy);
else
pDC->LineTo(xx, yy);
}


}

Re: テストが近づいてきてるので・・・

Posted: 2014年7月08日(火) 21:49
by みけCAT
とりあえず、コードを提示するときはBBcodeを有効にした状態でcodeタグで囲み、
かつ適切なインデントをしていただけると、見やすくて助かります。

Re: テストが近づいてきてるので・・・

Posted: 2014年7月08日(火) 22:54
by みけCAT
テストの問題がどのような感じかはわかりませんが、とりあえず適当に。

コード:

/* math.hの内容をここに挿入する */
#include"math.h"
/* これ以降のpiという文字列を3.14という文字列に置き換える */
#define pi 3.14
/* 関数を宣言する */
void Ctest1Dlg::OnBnClickedButton1()
{
	// TODO: ここにコントロール通知ハンドラー コードを追加します。

	/* 描画用の情報を得る */
	CWnd*h=GetDlgItem(IDC_PICTURE);
	CDC*pDC=h->GetDC();
	CRect r;
	/* 描画エリアの大きさを取得する */
	h->GetClientRect(&r);
	/* 描画エリアを白で塗りつぶす */
	pDC->FillSolidRect(r, RGB(255, 255, 255));

	/* 各種変数を宣言する */
	CString CentX, CentY, A, B, BETA;
	int centx, centy, a, b, i, x, y, xx, yy;
	double rd=pi/180, beta;

	/* 各オブジェクトへの参照を得る */
	CEdit* x00=(CEdit*)GetDlgItem(IDC_EDIT1);
	CEdit* y00=(CEdit*)GetDlgItem(IDC_EDIT2);
	CEdit* a00=(CEdit*)GetDlgItem(IDC_EDIT3);
	CEdit* b00=(CEdit*)GetDlgItem(IDC_EDIT4);
	CEdit* beta00=(CEdit*)GetDlgItem(IDC_EDIT5);

	/* 各種パラメータを取得する */
	x00->GetWindowTextW(CentX);
	y00->GetWindowTextW(CentY);
	a00->GetWindowTextW(A);
	b00->GetWindowTextW(B);
	beta00->GetWindowTextW(BETA);

	/* 取得したパラメータを数値に変換する */
	centx=_ttoi(CentX);
	centy=_ttoi(CentY);
	a=_ttoi(A);
	b=_ttoi(B);
	beta=_ttof(BETA);

	/* iを最初0にして、1ずつ足しながらiが360未満の間繰り返す */
	for(i=0; i<360; i++){
		/* 楕円上の座標を計算する */
		x=int(a*cos(i*rd));
		y=int(b*sin(i*rd));

		/* 平行移動と回転を反映した座標を計算する */
		xx=centx+int(x*cos(beta*rd)-y*sin(beta*rd));
		yy=centy+int(x*sin(beta*rd)+y*cos(beta*rd));

		/* ループ初回なら */
		if(i==0)
		/* 現在位置を(xx,yy)に設定する */
		pDC->MoveTo(xx, yy);
		/* ループ2回目以降なら */
		else
		/* 現在位置から(xx,yy)に向かう線分を描画し、現在位置を(xx,yy)にする */
		pDC->LineTo(xx, yy);
	}


}