国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

【圖形學(xué)】探秘圖形學(xué)奧秘:圖形變換的解密與實(shí)戰(zhàn)

這篇具有很好參考價(jià)值的文章主要介紹了【圖形學(xué)】探秘圖形學(xué)奧秘:圖形變換的解密與實(shí)戰(zhàn)。希望對大家有所幫助。如果存在錯(cuò)誤或未考慮完全的地方,請大家不吝賜教,您也可以點(diǎn)擊"舉報(bào)違法"按鈕提交疑問。

【圖形學(xué)】探秘圖形學(xué)奧秘:圖形變換的解密與實(shí)戰(zhàn),# 【圖形學(xué)】,圖形變換,平移變換,旋轉(zhuǎn)變換,對稱變換,比例變換,C語言,C++

???個(gè)人主頁:Sarapines Programmer
???系列專欄:《圖形學(xué) | 圖像解碼》
?詩賦清音:云生高巔夢遠(yuǎn)游, 星光點(diǎn)綴碧海愁。 山川深邃情難晤, 劍氣凌云志自修。

【圖形學(xué)】探秘圖形學(xué)奧秘:圖形變換的解密與實(shí)戰(zhàn),# 【圖形學(xué)】,圖形變換,平移變換,旋轉(zhuǎn)變換,對稱變換,比例變換,C語言,C++

?文章來源地址http://www.zghlxwxcb.cn/news/detail-804872.html

目錄

??1. 初識模式識別

??2.?圖形變換

??2.1 開發(fā)環(huán)境及實(shí)現(xiàn)

??2.2 實(shí)驗(yàn)?zāi)康?/p>

??2.3 實(shí)驗(yàn)要求

??2.4 實(shí)驗(yàn)原理

??2.5 實(shí)驗(yàn)步驟

??2.5.1?平移變換

??2.5.2?旋轉(zhuǎn)變換

??2.5.3?對稱變換

??2.5.4?比例變換

??2.4 研究體會

??總結(jié)


??1. 初識模式識別

圖形學(xué)技術(shù)是一門涉及計(jì)算機(jī)圖形和圖像處理的學(xué)科,其目標(biāo)是通過算法和數(shù)學(xué)模型來創(chuàng)建、處理和呈現(xiàn)圖形和圖像。這項(xiàng)技術(shù)的應(yīng)用范圍非常廣泛,涵蓋了許多領(lǐng)域,包括計(jì)算機(jī)游戲、虛擬現(xiàn)實(shí)、計(jì)算機(jī)輔助設(shè)計(jì)(CAD)、醫(yī)學(xué)圖像處理、動畫制作等。

以下是圖形學(xué)技術(shù)的一些關(guān)鍵方面:

  1. 圖形生成和渲染: 圖形學(xué)技術(shù)用于生成和呈現(xiàn)視覺圖像。這包括三維圖形的創(chuàng)建、光照、陰影、顏色和紋理等方面的處理,以產(chǎn)生逼真的圖形。

  2. 計(jì)算機(jī)輔助設(shè)計(jì)(CAD): 在工程學(xué)和設(shè)計(jì)領(lǐng)域,圖形學(xué)技術(shù)被廣泛用于創(chuàng)建和編輯數(shù)字化的設(shè)計(jì)圖紙,促進(jìn)設(shè)計(jì)過程的可視化和交互。

  3. 計(jì)算機(jī)游戲和虛擬現(xiàn)實(shí): 圖形學(xué)技術(shù)是游戲開發(fā)和虛擬現(xiàn)實(shí)領(lǐng)域的核心。它用于創(chuàng)建游戲中的角色、場景、特效以及虛擬現(xiàn)實(shí)環(huán)境,提供沉浸式的視覺體驗(yàn)。

  4. 醫(yī)學(xué)圖像處理: 在醫(yī)學(xué)領(lǐng)域,圖形學(xué)技術(shù)被用于處理和呈現(xiàn)醫(yī)學(xué)圖像,如CT掃描、MRI等,以協(xié)助醫(yī)生進(jìn)行診斷和手術(shù)規(guī)劃。

  5. 動畫制作: 圖形學(xué)技術(shù)是制作動畫的關(guān)鍵。通過在計(jì)算機(jī)上生成圖形幀并進(jìn)行渲染,動畫制作得以實(shí)現(xiàn)。

  6. 圖像處理: 圖形學(xué)技術(shù)也包括對靜態(tài)圖像的處理,如圖像編輯、濾鏡應(yīng)用、圖像合成等。

在圖形學(xué)技術(shù)的發(fā)展中,硬件加速、實(shí)時(shí)渲染、虛擬現(xiàn)實(shí)和增強(qiáng)現(xiàn)實(shí)等方面的創(chuàng)新不斷推動著圖形學(xué)的前沿。這門技術(shù)為數(shù)字世界的可視化和交互提供了強(qiáng)大的工具和方法。


??2.?圖形變換

??2.1 開發(fā)環(huán)境及實(shí)現(xiàn)

  • 語言: C++
  • 平臺: Microsoft Visual Studio 2022

??2.2 實(shí)驗(yàn)?zāi)康?/strong>

  • 進(jìn)行二維圖形的各種幾何變換,利用基本圖形實(shí)現(xiàn)。

??2.3 實(shí)驗(yàn)要求

  1. 使用Microsoft Visual Studio 2022編程。
  2. 實(shí)現(xiàn)以下幾何變換:
    • 平移變換
    • 旋轉(zhuǎn)變換
    • 對稱變換
    • 比例變換。

??2.4 實(shí)驗(yàn)原理

圖形的幾何變換一般是指對圖形的幾何信息經(jīng)過變換后產(chǎn)生新的圖形,圖形幾何變換既可以看作是坐標(biāo)系不動而圖形變動,變動后的圖形在坐標(biāo)系中的坐標(biāo)值發(fā)生變化;出可以看作圖形不動而坐標(biāo)系變動,變動后的圖形在新坐標(biāo)系下具有新的坐標(biāo)值。這兩種情況本質(zhì)上都是一樣的,都是圖形由新的坐標(biāo)值表示,因此是新產(chǎn)生的圖形。圖形幾何變換包括比例變換、對稱變換、錯(cuò)切變換、旋轉(zhuǎn)變換、平移變換及其復(fù)合變換。圖形上所有的點(diǎn)在幾何變換前后的坐標(biāo)關(guān)系一般用解析幾何方法可以求得,但這些幾何關(guān)系用矩陣方法表示,運(yùn)算更為方便。

圖形基本幾何變換是指比例變換、對稱變換、錯(cuò)切變換、旋轉(zhuǎn)變換和平移變換等。除平移變換外,這里其它四種幾何變換都可以用組成圖形的點(diǎn)向量(或稱1×2階矩陣)和2×2階變換矩陣相乘表示,而平移變換需引入新方法來實(shí)現(xiàn)。


??2.5 實(shí)驗(yàn)步驟

對圖形分別進(jìn)行平移變換、旋轉(zhuǎn)變換、對稱變換以及比例變換。

程序代碼示例如下:


??2.5.1?平移變換
#include <GL/glut.h>
#include <stdlib.h>
#include <math.h>

GLsizei winWidth = 600, winHeight = 600;
GLfloat xwcMin = 0.0, xwcMax = 225.0;
GLfloat ywcMin = 0.0, ywcMax = 225.0;

class wcPt2D
{
public:
	GLfloat x, y;
};

typedef GLfloat Matrix3x3[3][3];

Matrix3x3 matComposite;

const GLdouble pi = 3.14159;

void Init()
{
	glClearColor(1.0, 1.0, 1.0, 0.0);
}

void Matrix3x3SetIdentity(Matrix3x3 matIdent3x3)
{
	GLint row, col;

	for (row = 0; row < 3; row++)
	{
		for (col = 0; col < 3; col++)
		{
			matIdent3x3[row][col] = (row == col);
		}
	}
}

void Matrix3x3PreMultiply(Matrix3x3 m1, Matrix3x3 m2)
{
	GLint row, col;
	Matrix3x3 matTemp;

	for (row = 0; row < 3; row++)
	{
		for (col = 0; col < 3; col++)
		{
			matTemp[row][col] =
				m1[row][0] * m2[0][col] +
				m1[row][1] * m2[1][col] +
				m1[row][2] * m2[2][col];
		}
	}

	for (row = 0; row < 3; row++)
	{
		for (col = 0; col < 3; col++)
		{
			m2[row][col] = matTemp[row][col];
		}
	}
}

void Translate2D(GLfloat tx, GLfloat ty)
{
	Matrix3x3 matTransl;
	Matrix3x3SetIdentity(matTransl);
	matTransl[0][2] = tx;
	matTransl[1][2] = ty;
	Matrix3x3PreMultiply(matTransl, matComposite);
}


void TransformVerts2D(GLint nVerts, wcPt2D* verts)//平移函數(shù)實(shí)現(xiàn)
{
	GLint k;
	GLfloat temp;

	for (k = 0; k < nVerts; k++)
	{
		temp = matComposite[0][0] * verts[k].x +
			matComposite[0][1] * verts[k].y +
			matComposite[0][2];

		verts[k].y = matComposite[1][0] * verts[k].x +
			matComposite[1][1] * verts[k].y +
			matComposite[1][2];
		verts[k].x = temp;
	}
}

void Trangle(wcPt2D* verts)
{
	GLint k;

	glBegin(GL_TRIANGLES);
	for (k = 0; k < 3; k++)
	{
		glVertex2f(verts[k].x, verts[k].y);
	}
	glEnd();
}

void WinReshapFcn(GLint newWidth, GLint newHeight)
{
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	gluOrtho2D(xwcMin, xwcMax, ywcMin, ywcMax);

	glClear(GL_COLOR_BUFFER_BIT);
}

void DisplayFcn()
{
	glClear(GL_COLOR_BUFFER_BIT);
	GLint nVerts = 3;
	wcPt2D verts[3] = { {50,25},{150,25 },{100,100} };

	wcPt2D centroidPt;

	GLint k, xSum = 0, ySum = 0;

	for (size_t k = 0; k < nVerts; k++)
	{
		xSum += verts[k].x;
		ySum += verts[k].y;
	}

	centroidPt.x = GLfloat(xSum) / GLfloat(nVerts);
	centroidPt.y = GLfloat(ySum) / GLfloat(nVerts);

	wcPt2D pivPt, fixedPt;
	pivPt = centroidPt;
	fixedPt = centroidPt;

	GLfloat tx = 0, ty = 100;
	GLfloat sx = 0.5, sy = 0.5;
	GLdouble theta = pi / 2;
	glColor3f(0, 0, 1);
	Trangle(verts);
	Matrix3x3SetIdentity(matComposite);
	Translate2D(tx, ty);
	TransformVerts2D(nVerts, verts);//調(diào)用函數(shù)
	glColor3f(1, 0, 0);
	Trangle(verts);
	glFlush();
}

void draw_pixel(int ix, int iy)
{
	glBegin(GL_POINTS);
	glVertex2i(ix, iy);
	glEnd();
}

void myinit()
{
	glClearColor(1.0, 0.8, 1.0, 1.0);
	glColor3f(0.0, 0.5, 0.5);
	glPointSize(1.0);
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	gluOrtho2D(0.0, 1000.0, 0.0, 1000.0);
}
int main(int argc, char** argv)
{
	glutInit(&argc, argv);
	glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
	glutInitWindowSize(600, 500);
	glutInitWindowPosition(150.0, 150.0);
	glutCreateWindow("圖像平移變換");
	glutDisplayFunc(DisplayFcn);
	glutReshapeFunc(WinReshapFcn);
	myinit();
	glutMainLoop();
}

運(yùn)行結(jié)果

【圖形學(xué)】探秘圖形學(xué)奧秘:圖形變換的解密與實(shí)戰(zhàn),# 【圖形學(xué)】,圖形變換,平移變換,旋轉(zhuǎn)變換,對稱變換,比例變換,C語言,C++?


??2.5.2?旋轉(zhuǎn)變換
#include <GL/glut.h>
#include <stdlib.h>
#include <math.h>

GLsizei winWidth = 600, winHeight = 600;

GLfloat xwcMin = 0.0, xwcMax = 225.0;
GLfloat ywcMin = 0.0, ywcMax = 225.0;

class wcPt2D
{
public:
	GLfloat x, y;
};

typedef GLfloat Matrix3x3[3][3];

Matrix3x3 matComposite;

const GLdouble pi = 3.14159;

void Init()
{
	glClearColor(1.0, 1.0, 1.0, 0.0);
}

void Matrix3x3SetIdentity(Matrix3x3 matIdent3x3)
{
	GLint row, col;

	for (row = 0; row < 3; row++)
	{
		for (col = 0; col < 3; col++)
		{
			matIdent3x3[row][col] = (row == col);
		}
	}
}

void Matrix3x3PreMultiply(Matrix3x3 m1, Matrix3x3 m2)
{
	GLint row, col;
	Matrix3x3 matTemp;

	for (row = 0; row < 3; row++)
	{
		for (col = 0; col < 3; col++)
		{
			matTemp[row][col] =
				m1[row][0] * m2[0][col] +
				m1[row][1] * m2[1][col] +
				m1[row][2] * m2[2][col];
		}
	}

	for (row = 0; row < 3; row++)
	{
		for (col = 0; col < 3; col++)
		{
			m2[row][col] = matTemp[row][col];
		}
	}
}

void Translate2D(GLfloat tx, GLfloat ty)
{
	Matrix3x3 matTransl;

	Matrix3x3SetIdentity(matTransl);

	matTransl[0][2] = tx;
	matTransl[1][2] = ty;

	Matrix3x3PreMultiply(matTransl, matComposite);
}

void Rotate2D(wcPt2D pivotPt, GLfloat theta)//旋轉(zhuǎn)
{
	Matrix3x3 matRot;

	Matrix3x3SetIdentity(matRot);

	matRot[0][0] = cos(theta);
	matRot[0][1] = -sin(theta);
	matRot[0][2] = pivotPt.x * (1 - cos(theta)) +
		pivotPt.y * sin(theta);

	matRot[1][0] = sin(theta);
	matRot[1][1] = cos(theta);
	matRot[1][2] = pivotPt.y * (1 - cos(theta)) -
		pivotPt.x * sin(theta);

	Matrix3x3PreMultiply(matRot, matComposite);
}

void TransformVerts2D(GLint nVerts, wcPt2D* verts)//平移
{
	GLint k;
	GLfloat temp;

	for (k = 0; k < nVerts; k++)
	{
		temp = matComposite[0][0] * verts[k].x +
			matComposite[0][1] * verts[k].y +
			matComposite[0][2];

		verts[k].y = matComposite[1][0] * verts[k].x +
			matComposite[1][1] * verts[k].y +
			matComposite[1][2];
		verts[k].x = temp;
	}
}

void Trangle(wcPt2D* verts)
{
	GLint k;

	glBegin(GL_TRIANGLES);
	for (k = 0; k < 3; k++)
	{
		glVertex2f(verts[k].x, verts[k].y);
	}
	glEnd();
}

void WinReshapFcn(GLint newWidth, GLint newHeight)
{
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	gluOrtho2D(xwcMin, xwcMax, ywcMin, ywcMax);

	glClear(GL_COLOR_BUFFER_BIT);
}

void DisplayFcn()
{
	GLint nVerts = 3;
	wcPt2D verts[3] = { {50,25},{150,25 },{100,100} };

	wcPt2D centroidPt;

	GLint k, xSum = 0, ySum = 0;

	for (size_t k = 0; k < nVerts; k++)
	{
		xSum += verts[k].x;
		ySum += verts[k].y;
	}

	centroidPt.x = GLfloat(xSum) / GLfloat(nVerts);
	centroidPt.y = GLfloat(ySum) / GLfloat(nVerts);

	wcPt2D pivPt, fixedPt;
	pivPt = centroidPt;
	fixedPt = centroidPt;

	GLfloat tx = 0, ty = 100;
	GLfloat sx = 0.5, sy = 0.5;
	GLdouble theta = pi / 2;
	glClear(GL_COLOR_BUFFER_BIT);
	glColor3f(0, 0, 1);
	Trangle(verts);
	Matrix3x3SetIdentity(matComposite);
	Rotate2D(pivPt, theta);
	Translate2D(tx, ty);

	TransformVerts2D(nVerts, verts);

	glColor3f(1, 0, 0);
	Trangle(verts);

	glFlush();
}
void draw_pixel(int ix, int iy)
{
	glBegin(GL_POINTS);
	glVertex2i(ix, iy);
	glEnd();
}

void myinit()
{
	glClearColor(1.0, 0.8, 1.0, 1.0);
	glColor3f(0.0, 0.5, 0.5);
	glPointSize(1.0);
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	gluOrtho2D(0.0, 1000.0, 0.0, 1000.0);
}
int main(int argc, char** argv)
{
	glutInit(&argc, argv);
	glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
	glutInitWindowSize(600, 500);
	glutInitWindowPosition(150.0, 150.0);
	glutCreateWindow("圖像旋轉(zhuǎn)變換");
	glutDisplayFunc(DisplayFcn);
	glutReshapeFunc(WinReshapFcn);
	myinit();
	glutMainLoop();
}

運(yùn)行結(jié)果

?【圖形學(xué)】探秘圖形學(xué)奧秘:圖形變換的解密與實(shí)戰(zhàn),# 【圖形學(xué)】,圖形變換,平移變換,旋轉(zhuǎn)變換,對稱變換,比例變換,C語言,C++


??2.5.3?對稱變換
#include <GL/glut.h>
#include <stdlib.h>
#include <math.h>

GLsizei winWidth = 600, winHeight = 600;

GLfloat xwcMin = 0.0, xwcMax = 225.0;
GLfloat ywcMin = 0.0, ywcMax = 225.0;

class wcPt2D
{
public:
	GLfloat x, y;
};

typedef GLfloat Matrix3x3[3][3];

Matrix3x3 matComposite;

const GLdouble pi = 3.14159;

void Init()
{
	glClearColor(1.0, 1.0, 1.0, 0.0);
}

void Matrix3x3SetIdentity(Matrix3x3 matIdent3x3)
{
	GLint row, col;

	for (row = 0; row < 3; row++)
	{
		for (col = 0; col < 3; col++)
		{
			matIdent3x3[row][col] = (row == col);
		}
	}
}

void Matrix3x3PreMultiply(Matrix3x3 m1, Matrix3x3 m2)
{
	GLint row, col;
	Matrix3x3 matTemp;

	for (row = 0; row < 3; row++)
	{
		for (col = 0; col < 3; col++)
		{
			matTemp[row][col] =
				m1[row][0] * m2[0][col] +
				m1[row][1] * m2[1][col] +
				m1[row][2] * m2[2][col];
		}
	}

	for (row = 0; row < 3; row++)
	{
		for (col = 0; col < 3; col++)
		{
			m2[row][col] = matTemp[row][col];
		}
	}
}

void Translate2D(GLfloat tx, GLfloat ty)
{
	Matrix3x3 matTransl;

	Matrix3x3SetIdentity(matTransl);

	matTransl[0][2] = tx;
	matTransl[1][2] = ty;

	Matrix3x3PreMultiply(matTransl, matComposite);
}

void Rotate2D(wcPt2D pivotPt, GLfloat theta)//旋轉(zhuǎn)
{
	Matrix3x3 matRot;

	Matrix3x3SetIdentity(matRot);

	matRot[0][0] = cos(theta);
	matRot[0][1] = -sin(theta);
	matRot[0][2] = pivotPt.x * (1 - cos(theta)) +
		pivotPt.y * sin(theta);

	matRot[1][0] = sin(theta);
	matRot[1][1] = cos(theta);
	matRot[1][2] = pivotPt.y * (1 - cos(theta)) -
		pivotPt.x * sin(theta);

	Matrix3x3PreMultiply(matRot, matComposite);
}

void TransformVerts2D(GLint nVerts, wcPt2D* verts)//平移
{
	GLint k;
	GLfloat temp;

	for (k = 0; k < nVerts; k++)
	{
		temp = matComposite[0][0] * verts[k].x +
			matComposite[0][1] * verts[k].y +
			matComposite[0][2];

		verts[k].y = matComposite[1][0] * verts[k].x +
			matComposite[1][1] * verts[k].y +
			matComposite[1][2];
		verts[k].x = temp;
	}
}

void Trangle(wcPt2D* verts)
{
	GLint k;

	glBegin(GL_TRIANGLES);
	for (k = 0; k < 3; k++)
	{
		glVertex2f(verts[k].x, verts[k].y);
	}
	glEnd();
}

void WinReshapFcn(GLint newWidth, GLint newHeight)
{
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	gluOrtho2D(xwcMin, xwcMax, ywcMin, ywcMax);

	glClear(GL_COLOR_BUFFER_BIT);
}

void DisplayFcn()
{
	GLint nVerts = 3;
	wcPt2D verts[3] = { {50,25},{150,25 },{100,100} };

	wcPt2D centroidPt;

	GLint k, xSum = 0, ySum = 0;

	for (size_t k = 0; k < nVerts; k++)
	{
		xSum += verts[k].x;
		ySum += verts[k].y;
	}

	centroidPt.x = GLfloat(xSum) / GLfloat(nVerts);
	centroidPt.y = GLfloat(ySum) / GLfloat(nVerts);

	wcPt2D pivPt, fixedPt;
	pivPt = centroidPt;
	fixedPt = centroidPt;

	GLfloat tx = 0, ty = 100;
	GLfloat sx = 0.5, sy = 0.5;
	GLdouble theta = pi;

	glClear(GL_COLOR_BUFFER_BIT);

	glColor3f(0, 0, 1);
	Trangle(verts);
	Matrix3x3SetIdentity(matComposite);
	Rotate2D(pivPt, theta);
	Translate2D(tx, ty);

	TransformVerts2D(nVerts, verts);

	glColor3f(1, 0, 0);
	Trangle(verts);

	glFlush();
}

void draw_pixel(int ix, int iy)
{
	glBegin(GL_POINTS);
	glVertex2i(ix, iy);
	glEnd();
}

void myinit()
{
	glClearColor(1.0, 0.8, 1.0, 1.0);
	glColor3f(0.0, 0.5, 0.5);
	glPointSize(1.0);
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	gluOrtho2D(0.0, 1000.0, 0.0, 1000.0);
}
int main(int argc, char** argv)
{
	glutInit(&argc, argv);
	glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
	glutInitWindowSize(600, 500);
	glutInitWindowPosition(150.0, 150.0);
	glutCreateWindow("圖像對稱變換");
	glutDisplayFunc(DisplayFcn);
	glutReshapeFunc(WinReshapFcn);
	myinit();
	glutMainLoop();
}

運(yùn)行結(jié)果

【圖形學(xué)】探秘圖形學(xué)奧秘:圖形變換的解密與實(shí)戰(zhàn),# 【圖形學(xué)】,圖形變換,平移變換,旋轉(zhuǎn)變換,對稱變換,比例變換,C語言,C++?


??2.5.4?比例變換
#include <GL/glut.h>
#include <stdlib.h>
#include <math.h>

GLsizei winWidth = 600, winHeight = 600;

GLfloat xwcMin = 0.0, xwcMax = 225.0;
GLfloat ywcMin = 0.0, ywcMax = 225.0;

class wcPt2D
{
public:
	GLfloat x, y;
};

typedef GLfloat Matrix3x3[3][3];

Matrix3x3 matComposite;

const GLdouble pi = 3.14159;

void Init()
{
	glClearColor(1.0, 1.0, 1.0, 0.0);
}

void Matrix3x3SetIdentity(Matrix3x3 matIdent3x3)
{
	GLint row, col;

	for (row = 0; row < 3; row++)
	{
		for (col = 0; col < 3; col++)
		{
			matIdent3x3[row][col] = (row == col);
		}
	}
}

void Matrix3x3PreMultiply(Matrix3x3 m1, Matrix3x3 m2)
{
	GLint row, col;
	Matrix3x3 matTemp;

	for (row = 0; row < 3; row++)
	{
		for (col = 0; col < 3; col++)
		{
			matTemp[row][col] =
				m1[row][0] * m2[0][col] +
				m1[row][1] * m2[1][col] +
				m1[row][2] * m2[2][col];
		}
	}

	for (row = 0; row < 3; row++)
	{
		for (col = 0; col < 3; col++)
		{
			m2[row][col] = matTemp[row][col];
		}
	}
}

void Translate2D(GLfloat tx, GLfloat ty)
{
	Matrix3x3 matTransl;

	Matrix3x3SetIdentity(matTransl);

	matTransl[0][2] = tx;
	matTransl[1][2] = ty;

	Matrix3x3PreMultiply(matTransl, matComposite);
}

void Scale2D(GLfloat sx, GLfloat sy, wcPt2D fixedPt)//縮放
{
	Matrix3x3 matScale;

	Matrix3x3SetIdentity(matScale);

	matScale[0][0] = sx;
	matScale[0][2] = (1 - sx) * fixedPt.x;

	matScale[1][1] = sy;
	matScale[1][2] = (1 - sy) * fixedPt.y;

	Matrix3x3PreMultiply(matScale, matComposite);
}

void TransformVerts2D(GLint nVerts, wcPt2D* verts)//平移
{
	GLint k;
	GLfloat temp;

	for (k = 0; k < nVerts; k++)
	{
		temp = matComposite[0][0] * verts[k].x +
			matComposite[0][1] * verts[k].y +
			matComposite[0][2];

		verts[k].y = matComposite[1][0] * verts[k].x +
			matComposite[1][1] * verts[k].y +
			matComposite[1][2];
		verts[k].x = temp;
	}
}

void Trangle(wcPt2D* verts)
{
	GLint k;

	glBegin(GL_TRIANGLES);
	for (k = 0; k < 3; k++)
	{
		glVertex2f(verts[k].x, verts[k].y);
	}
	glEnd();
}

void WinReshapFcn(GLint newWidth, GLint newHeight)
{
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	gluOrtho2D(xwcMin, xwcMax, ywcMin, ywcMax);

	glClear(GL_COLOR_BUFFER_BIT);
}

void DisplayFcn()
{
	GLint nVerts = 3;
	wcPt2D verts[3] = { {50,25},{150,25 },{100,100} };

	wcPt2D centroidPt;

	GLint k, xSum = 0, ySum = 0;

	for (size_t k = 0; k < nVerts; k++)
	{
		xSum += verts[k].x;
		ySum += verts[k].y;
	}

	centroidPt.x = GLfloat(xSum) / GLfloat(nVerts);
	centroidPt.y = GLfloat(ySum) / GLfloat(nVerts);

	wcPt2D pivPt, fixedPt;
	pivPt = centroidPt;
	fixedPt = centroidPt;

	GLfloat tx = 0, ty = 100;
	GLfloat sx = 0.5, sy = 0.5;
	GLdouble theta = pi / 2;

	glClear(GL_COLOR_BUFFER_BIT);

	glColor3f(0, 0, 1);
	Trangle(verts);

	Matrix3x3SetIdentity(matComposite);

	Scale2D(sx, sy, fixedPt);
	Translate2D(tx, ty);

	TransformVerts2D(nVerts, verts);

	glColor3f(1, 0, 0);
	Trangle(verts);

	glFlush();
}

void draw_pixel(int ix, int iy)
{
	glBegin(GL_POINTS);
	glVertex2i(ix, iy);
	glEnd();
}

void myinit()
{
	glClearColor(1.0, 0.8, 1.0, 1.0);
	glColor3f(0.0, 0.5, 0.5);
	glPointSize(1.0);
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	gluOrtho2D(0.0, 1000.0, 0.0, 1000.0);
}
int main(int argc, char** argv)
{
	glutInit(&argc, argv);
	glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
	glutInitWindowSize(600, 500);
	glutInitWindowPosition(150.0, 150.0);
	glutCreateWindow("圖像比例變換");
	glutDisplayFunc(DisplayFcn);
	glutReshapeFunc(WinReshapFcn);
	myinit();
	glutMainLoop();
}

運(yùn)行結(jié)果

【圖形學(xué)】探秘圖形學(xué)奧秘:圖形變換的解密與實(shí)戰(zhàn),# 【圖形學(xué)】,圖形變換,平移變換,旋轉(zhuǎn)變換,對稱變換,比例變換,C語言,C++?


??2.4 研究體會

  1. 實(shí)驗(yàn)內(nèi)容完成: 通過本次實(shí)驗(yàn),我成功地完成了圖像平移、旋轉(zhuǎn)、對稱和比例縮放等變換操作。為了提高圖像顯示效果的清晰度,我在旋轉(zhuǎn)、對稱和縮放變換中添加了平移操作,以避免變換后的圖像與原圖重疊。這使我對圖像變換操作有了深入的理解和實(shí)際操作經(jīng)驗(yàn)。

  2. 自學(xué)與應(yīng)用場景差距: 通過構(gòu)造幾何圖像并進(jìn)行變換操作,我意識到在實(shí)際應(yīng)用場景中,通常是對給定的圖像進(jìn)行變換操作,而不是自己構(gòu)造圖像。雖然我在Python中對圖像操作較為熟悉,但在C++中感覺到需要從頭編寫并控制每個(gè)功能。盡管這樣的學(xué)習(xí)方式較為理想,但在實(shí)際應(yīng)用中可能需要更多的庫函數(shù)支持。

  3. 學(xué)習(xí)過程中的挑戰(zhàn)和成就感: 實(shí)驗(yàn)中我花費(fèi)了較多時(shí)間在圖像生成的控制上,包括輸出面板底色、圖像初始位置和輸出框大小等方面。由于之前主要在Dev-C++平臺編程,初次使用Visual Studio 2022平臺感到不太順手,但通過自學(xué)和網(wǎng)上查找資料逐漸適應(yīng)。最終看到運(yùn)行結(jié)果時(shí),感受到了付出的回報(bào),同時(shí)也認(rèn)識到在學(xué)習(xí)過程中需要保持耐心和專注。這次實(shí)驗(yàn)使我更加深入地了解了圖形學(xué),也激發(fā)了我對編程的熱情和學(xué)習(xí)的動力。


??總結(jié)

圖形學(xué)領(lǐng)域宛如一片廣闊而未被完全探索的創(chuàng)意海洋,邀請你勇敢踏足數(shù)字藝術(shù)和計(jì)算機(jī)圖形學(xué)的神秘領(lǐng)域。這是一場富有創(chuàng)意和技術(shù)挑戰(zhàn)的學(xué)習(xí)之旅,從基礎(chǔ)概念到算法實(shí)現(xiàn),逐步揭示更深層次的圖形分析、渲染技術(shù)和智能圖形識別的奧秘??释魬?zhàn)圖形學(xué)的學(xué)習(xí)路徑和掌握計(jì)算機(jī)藝術(shù)的技能?不妨點(diǎn)擊下方鏈接,一同探討更多數(shù)字創(chuàng)意的奇跡吧。我們推出了引領(lǐng)趨勢的?? 計(jì)算機(jī)圖形學(xué)專欄:《藝術(shù)之光 | 數(shù)字創(chuàng)新解鎖》,旨在深度探索圖形學(xué)技術(shù)的實(shí)際應(yīng)用和創(chuàng)新。????

【圖形學(xué)】探秘圖形學(xué)奧秘:圖形變換的解密與實(shí)戰(zhàn),# 【圖形學(xué)】,圖形變換,平移變換,旋轉(zhuǎn)變換,對稱變換,比例變換,C語言,C++

?

到了這里,關(guān)于【圖形學(xué)】探秘圖形學(xué)奧秘:圖形變換的解密與實(shí)戰(zhàn)的文章就介紹完了。如果您還想了解更多內(nèi)容,請?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點(diǎn)僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實(shí)不符,請點(diǎn)擊違法舉報(bào)進(jìn)行投訴反饋,一經(jīng)查實(shí),立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費(fèi)用

相關(guān)文章

  • 【Linux操作系統(tǒng)】探秘Linux奧秘:日志管理的解密與實(shí)戰(zhàn)

    【Linux操作系統(tǒng)】探秘Linux奧秘:日志管理的解密與實(shí)戰(zhàn)

    ??個(gè)人主頁: Sarapines Programmer ???系列專欄: 《操作系統(tǒng)實(shí)驗(yàn)室》 ??詩賦清音:柳垂輕絮拂人衣,心隨風(fēng)舞夢飛。 山川湖海皆可涉,勇者征途逐星輝。 目錄 ??1 初識Linux OS ??2?日志管理的解密與實(shí)戰(zhàn) ??1. 實(shí)驗(yàn)?zāi)康???2. 實(shí)驗(yàn)準(zhǔn)備 ??3. 實(shí)驗(yàn)內(nèi)容 ??4. 實(shí)驗(yàn)心得 ??總結(jié)

    2024年02月03日
    瀏覽(20)
  • 【Linux操作系統(tǒng)】探秘Linux奧秘:shell 編程的解密與實(shí)戰(zhàn)

    【Linux操作系統(tǒng)】探秘Linux奧秘:shell 編程的解密與實(shí)戰(zhàn)

    ??個(gè)人主頁: Sarapines Programmer ???系列專欄: 《操作系統(tǒng)實(shí)驗(yàn)室》 ??詩賦清音:柳垂輕絮拂人衣,心隨風(fēng)舞夢飛。 山川湖海皆可涉,勇者征途逐星輝。 目錄 ??1 初識Linux OS ??2?shell 編程的解密與實(shí)戰(zhàn) ??1. 實(shí)驗(yàn)?zāi)康???2. 實(shí)驗(yàn)準(zhǔn)備 ??3. 實(shí)驗(yàn)內(nèi)容 ??4. 實(shí)驗(yàn)心得 ??總結(jié)

    2024年02月03日
    瀏覽(25)
  • 【Linux操作系統(tǒng)】探秘Linux奧秘:進(jìn)程與任務(wù)管理的解密與實(shí)戰(zhàn)

    【Linux操作系統(tǒng)】探秘Linux奧秘:進(jìn)程與任務(wù)管理的解密與實(shí)戰(zhàn)

    ??個(gè)人主頁: Sarapines Programmer ???系列專欄: 《操作系統(tǒng)實(shí)驗(yàn)室》 ??詩賦清音:柳垂輕絮拂人衣,心隨風(fēng)舞夢飛。 山川湖海皆可涉,勇者征途逐星輝。 目錄 ??1 初識Linux OS ??2?進(jìn)程與任務(wù)管理的解密與實(shí)戰(zhàn) ??1. 實(shí)驗(yàn)?zāi)康???2. 實(shí)驗(yàn)準(zhǔn)備 ??3. 實(shí)驗(yàn)內(nèi)容 ??4. 實(shí)驗(yàn)心得 ??

    2024年02月03日
    瀏覽(19)
  • 【Linux操作系統(tǒng)】探秘Linux奧秘:Linux開發(fā)工具的解密與實(shí)戰(zhàn)

    【Linux操作系統(tǒng)】探秘Linux奧秘:Linux開發(fā)工具的解密與實(shí)戰(zhàn)

    ??個(gè)人主頁: Sarapines Programmer ???系列專欄: 《操作系統(tǒng)實(shí)驗(yàn)室》 ??詩賦清音:柳垂輕絮拂人衣,心隨風(fēng)舞夢飛。 山川湖海皆可涉,勇者征途逐星輝。 目錄 ??1 初識Linux OS ??2?Linux開發(fā)工具的解密與實(shí)戰(zhàn) ??1. 實(shí)驗(yàn)?zāi)康???2. 實(shí)驗(yàn)準(zhǔn)備 ??3. 實(shí)驗(yàn)內(nèi)容 ??4. 實(shí)驗(yàn)心得 ??總

    2024年02月03日
    瀏覽(52)
  • 【Linux操作系統(tǒng)】探秘Linux奧秘:Linux 操作系統(tǒng)的解密與實(shí)戰(zhàn)

    【Linux操作系統(tǒng)】探秘Linux奧秘:Linux 操作系統(tǒng)的解密與實(shí)戰(zhàn)

    ??個(gè)人主頁: Sarapines Programmer ???系列專欄: 《操作系統(tǒng)實(shí)驗(yàn)室》 ??詩賦清音:柳垂輕絮拂人衣,心隨風(fēng)舞夢飛。 山川湖海皆可涉,勇者征途逐星輝。 目錄 ??1 初識Linux OS ??2. Linux 操作系統(tǒng)的解密與實(shí)戰(zhàn) ??1. 實(shí)驗(yàn)?zāi)康???2. 實(shí)驗(yàn)準(zhǔn)備 ??3. 實(shí)驗(yàn)內(nèi)容 ??4. 實(shí)驗(yàn)心得 ??總

    2024年02月03日
    瀏覽(28)
  • 【Linux操作系統(tǒng)】探秘Linux奧秘:用戶、組、密碼及權(quán)限管理的解密與實(shí)戰(zhàn)

    【Linux操作系統(tǒng)】探秘Linux奧秘:用戶、組、密碼及權(quán)限管理的解密與實(shí)戰(zhàn)

    ??個(gè)人主頁: Sarapines Programmer ???系列專欄: 《操作系統(tǒng)實(shí)驗(yàn)室》 ??詩賦清音:柳垂輕絮拂人衣,心隨風(fēng)舞夢飛。 山川湖海皆可涉,勇者征途逐星輝。 目錄 ??1 初識Linux OS ??2?用戶、組、密碼及權(quán)限管理的解密與實(shí)戰(zhàn) ??1. 實(shí)驗(yàn)?zāi)康???2. 實(shí)驗(yàn)準(zhǔn)備 ??3. 實(shí)驗(yàn)內(nèi)容 ??4

    2024年02月03日
    瀏覽(33)
  • 三維變換矩陣實(shí)戰(zhàn)——三維點(diǎn)云的旋轉(zhuǎn)、縮放、鏡像、錯(cuò)切、平移、正交投影

    三維變換矩陣實(shí)戰(zhàn)——三維點(diǎn)云的旋轉(zhuǎn)、縮放、鏡像、錯(cuò)切、平移、正交投影

    旋轉(zhuǎn)矩陣:右邊矩陣是點(diǎn)云的原始坐標(biāo),左邊的是旋轉(zhuǎn)矩陣 ??? 可視化:繞x軸旋轉(zhuǎn)90度 代碼: 旋轉(zhuǎn)矩陣: ?? 可視化:繞y軸旋轉(zhuǎn)180度 代碼: 旋轉(zhuǎn)矩陣: ?? 可視化:繞z軸旋轉(zhuǎn)90度 代碼: 旋轉(zhuǎn)矩陣:? 線繞哪個(gè)軸轉(zhuǎn),xyz矩陣就和哪和軸的旋轉(zhuǎn)矩陣先計(jì)算 ???? 可視化:先

    2024年02月04日
    瀏覽(31)
  • 【OpenCV】圖像變換(縮放、平移、旋轉(zhuǎn)、仿射)

    圖像變換是指通過對圖像進(jìn)行縮放、平移、旋轉(zhuǎn)、仿射、透視等變換來改變圖像的形狀和大小。在本篇博客中,我們將詳細(xì)介紹OpenCV中的圖像變換函數(shù),并提供示例代碼以幫助讀者更好地理解這些函數(shù)的使用方法。 縮放變換是指通過改變圖像的大小來改變圖像的形狀。在Op

    2024年02月07日
    瀏覽(94)
  • 二維坐標(biāo)基本變換(平移、旋轉(zhuǎn)、縮放、鏡像、陣列)

    二維坐標(biāo)基本變換(平移、旋轉(zhuǎn)、縮放、鏡像、陣列)

    諸如圖像、模型等的基本變換,實(shí)際上都是點(diǎn)坐標(biāo)的變換,通過矩陣,可以非常方便的達(dá)到這個(gè)目的。在下文僅介紹二維坐標(biāo)變換原理。 首先,定義點(diǎn)類如下: 注意,為了形式統(tǒng)一,變換矩陣應(yīng)統(tǒng)一為3*3階,同理,對于三維坐標(biāo)變換矩陣應(yīng)是4*4階。關(guān)于矩陣的表示,實(shí)際上

    2024年02月04日
    瀏覽(28)
  • 【計(jì)算機(jī)圖形學(xué)】圖形變換(以任意直線為對稱軸的對稱變換)

    【計(jì)算機(jī)圖形學(xué)】圖形變換(以任意直線為對稱軸的對稱變換)

    模塊3-2 圖形變換 一 實(shí)驗(yàn)?zāi)康?編寫圖形各種變換的算法 二 實(shí)驗(yàn)內(nèi)容 1 :任意直線的對稱變換。要求將變換矩陣寫在實(shí)驗(yàn)報(bào)告中,并與代碼匹配。求對任意直線Ax+By+C=0的對稱變換矩陣。 實(shí)驗(yàn)結(jié)果如下圖所示: 1:預(yù)設(shè)圖形初始化 2:鼠標(biāo)左鍵點(diǎn)擊直線起點(diǎn) 3:鼠標(biāo)右鍵點(diǎn)擊直線

    2024年02月01日
    瀏覽(55)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包