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

計(jì)算機(jī)圖形學(xué)頭歌實(shí)訓(xùn)平臺(tái)答案——CG1-v2.0-直線繪制

這篇具有很好參考價(jià)值的文章主要介紹了計(jì)算機(jī)圖形學(xué)頭歌實(shí)訓(xùn)平臺(tái)答案——CG1-v2.0-直線繪制。希望對(duì)大家有所幫助。如果存在錯(cuò)誤或未考慮完全的地方,請(qǐng)大家不吝賜教,您也可以點(diǎn)擊"舉報(bào)違法"按鈕提交疑問。

?第1關(guān):直線光柵化-DDA畫線算法

任務(wù)描述

1.本關(guān)任務(wù)

(1)根據(jù)直線DDA算法補(bǔ)全line函數(shù),其中直線斜率0<k<1; (2)當(dāng)直線方程恰好經(jīng)過P(x,y)和T(x,y+1)的中點(diǎn)M時(shí),統(tǒng)一選取直線上方的T點(diǎn)為顯示的像素點(diǎn)。

2.輸入

(1)直線兩端點(diǎn)坐標(biāo):(13, 20)和(180,140); (2)直線顏色為白色。

3.輸出

程序運(yùn)行結(jié)果為一條直線,具體結(jié)果如下圖所示:

計(jì)算機(jī)圖形學(xué)頭歌實(shí)訓(xùn)平臺(tái)答案——CG1-v2.0-直線繪制,計(jì)算機(jī)圖形學(xué)頭歌實(shí)訓(xùn)答案,頭歌作業(yè),算法,數(shù)據(jù)結(jié)構(gòu),c#,c語(yǔ)言,程序人生

整體代碼如下:

#include "tgaimage.h"

const TGAColor white = TGAColor(255, 255, 255, 255);
const TGAColor red = TGAColor(255, 0, 0, 255);

void line(int x0, int y0, int x1, int y1, TGAImage &image, TGAColor color)
{
    // Please add the code here
    /********** Begin ********/
    int x;
    float y, k;
    k = (float)(y1 - y0) / (float)(x1 - x0);
    y = y0;
    for (x = x0;x <= x1;x++)
    {
        image.set(x, int(y + 0.5f),color);
        y = y + k;
    }



    /********** End *********/
}

int main(int argc, char** argv)
{
	TGAImage image(640,480, TGAImage::RGB);
	line(13, 20, 180, 140, image, white);
	image.flip_vertically(); // i want to have the origin at the left bottom corner of the image
	image.write_tga_file("../img_step1/test.tga");

	return 0;
}

?為防止一些劉亦菲和吳彥祖?zhèn)兛床怀鰜?lái),那小Mo就把更加簡(jiǎn)潔的代碼放到下面啦

(有木有很貼心,還不給小Mo點(diǎn)個(gè)關(guān)注鼓勵(lì)一下??)

(begin和end之間的代碼):

代碼段一:

? ?/********** Begin ********/

? ? int x;

? ? float y, k;

? ? k = (float)(y1 - y0) / (float)(x1 - x0);

? ? y = y0;

? ? for (x = x0;x <= x1;x++)

? ? {

? ? ? ? image.set(x, int(y + 0.5f),color);

? ? ? ? y = y + k;

? ? }

? ? /********** End *********/文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-737748.html

第2關(guān):直線光柵化-中點(diǎn)畫線算法

任務(wù)描述

1.本關(guān)任務(wù)

(1)根據(jù)直線中點(diǎn)畫線算法補(bǔ)全line函數(shù),其中直線斜率0<k<1,并將main函數(shù)中的line函數(shù)參數(shù)補(bǔ)充完整; (2)當(dāng)直線方程恰好經(jīng)過P(x,y)和T(x,y+1)的中點(diǎn)M時(shí),統(tǒng)一選取直線上方的T點(diǎn)為顯示的像素點(diǎn)。

2.輸入

(1)直線兩端點(diǎn)坐標(biāo):(100, 100)和(520,300); (2)直線顏色為紅色。

3.輸出

程序運(yùn)行結(jié)果為一條直線,具體結(jié)果如下圖所示

計(jì)算機(jī)圖形學(xué)頭歌實(shí)訓(xùn)平臺(tái)答案——CG1-v2.0-直線繪制,計(jì)算機(jī)圖形學(xué)頭歌實(shí)訓(xùn)答案,頭歌作業(yè),算法,數(shù)據(jù)結(jié)構(gòu),c#,c語(yǔ)言,程序人生

整體代碼如下:

#include "tgaimage.h"

const TGAColor white = TGAColor(255, 255, 255, 255);
const TGAColor red = TGAColor(255, 0, 0, 255);

void line(int x1, int y1, int xn, int yn, TGAImage &image, TGAColor color)
{
    // Please add the code here
    /********** Begin ********/
    int dx,dy,dt,db,d,x,y;
        dx = xn - x1;
        dy = yn - y1;
        d = dx - 2*dy;
        dt = 2*dx - 2*dy;
        db = -2*dy;
        x = x1;y = y1;
        image.set(x,y,color);
        while (x < xn)
        {
            if (d <= 0)
            {    x++;
                y++;
                d += dt;
                }
        else
        {
            x++;
            d += db;
        }
        image.set(x,y,color);
        }




    /********** End *********/
}

int main(int argc, char** argv)
{
	TGAImage image(640,480, TGAImage::RGB);
    // Please add the code here
    /********** Begin ********/
	line( 100, 100 , 520 , 300 , image, red );
    /********** End *********/
	image.flip_vertically(); // i want to have the origin at the left bottom corner of the image
	image.write_tga_file("../img_step4/test.tga");
	return 0;
}

按照小Mo慣例,還是把需要填寫的代碼段po出來(lái)嘍~

代碼段一:

?/********** Begin ********/

? ? int dx,dy,dt,db,d,x,y;

? ? ? ? dx = xn - x1;

? ? ? ? dy = yn - y1;

? ? ? ? d = dx - 2*dy;

? ? ? ? dt = 2*dx - 2*dy;

? ? ? ? db = -2*dy;

? ? ? ? x = x1;y = y1;

? ? ? ? image.set(x,y,color);

? ? ? ? while (x < xn)

? ? ? ? {

? ? ? ? ? ? if (d <= 0)

? ? ? ? ? ? { ? ?x++;

? ? ? ? ? ? ? ? y++;

? ? ? ? ? ? ? ? d += dt;

? ? ? ? ? ? ? ? }

? ? ? ? else

? ? ? ? {

? ? ? ? ? ? x++;

? ? ? ? ? ? d += db;

? ? ? ? }

? ? ? ? image.set(x,y,color);

? ? ? ? }

? ? /********** End *********/

代碼段二:

? ? /********** Begin ********/

? ? line( 100, 100 , 520 , 300 , image, red );

? ? /********** End *********/

?第3關(guān):直線光柵化-Bresenham畫線算法

任務(wù)描述:

1.本關(guān)任務(wù)

(1)根據(jù)直線Bresenham算法補(bǔ)全line函數(shù),其中直線斜率0<k<1,并將main函數(shù)中的line函數(shù)參數(shù)補(bǔ)充完整; (2)當(dāng)直線方程恰好經(jīng)過P(x,y)和T(x,y+1)的中點(diǎn)M時(shí),統(tǒng)一選取直線上方的T點(diǎn)為顯示的像素點(diǎn)。

2.輸入

(1)直線兩端點(diǎn)坐標(biāo):(20, 20)和(180,140); (2)直線顏色為白色。

3.輸出

程序運(yùn)行結(jié)果為一條直線,具體結(jié)果如下圖所示:

計(jì)算機(jī)圖形學(xué)頭歌實(shí)訓(xùn)平臺(tái)答案——CG1-v2.0-直線繪制,計(jì)算機(jī)圖形學(xué)頭歌實(shí)訓(xùn)答案,頭歌作業(yè),算法,數(shù)據(jù)結(jié)構(gòu),c#,c語(yǔ)言,程序人生

整體代碼如下:

#include "tgaimage.h"

const TGAColor white = TGAColor(255, 255, 255, 255);
const TGAColor red = TGAColor(255, 0, 0, 255);

void line(int x0, int y0, int x1, int y1, TGAImage &image, TGAColor color)
{
    // Please add the code here
    /********** Begin ********/
    int dx = x1 - x0;
    int dy = y1 - y0;
    int y = y0;
    int d = -dx;
    for(int x = x0;x <=x1;x++)
    {
        image.set(x,y,color);
        d = d + 2*dy;
        if(d >= 0)
        {
            y++;
            d = d - 2*dx;
        }
    }


    /********** End *********/
}

int main(int argc, char** argv)
{
	TGAImage image(640,480, TGAImage::RGB);
    // Please add the code here
    /********** Begin ********/
	line( 20, 20 , 180 , 140 , image, white  );
    /********** End *********/
	image.flip_vertically(); // i want to have the origin at the left bottom corner of the image
	image.write_tga_file("../img_step2/test.tga");
	return 0;
}

同樣,小Mo還是會(huì)把需要填寫的代碼段po出來(lái)噠~

代碼段一:

? ? /********** Begin ********/

? ? int dx = x1 - x0;

? ? int dy = y1 - y0;

? ? int y = y0;

? ? int d = -dx;

? ? for(int x = x0;x <=x1;x++)

? ? {

? ? ? ? image.set(x,y,color);

? ? ? ? d = d + 2*dy;

? ? ? ? if(d >= 0)

? ? ? ? {

? ? ? ? ? ? y++;

? ? ? ? ? ? d = d - 2*dx;

? ? ? ? }

? ? }

? ? /********** End *********/

代碼段二:

? ? /********** Begin ********/? ?

? ?line( 20, 20 , 180 , 140 , image, white ?);

? ? /********** End **********/

第4關(guān):直線光柵化-任意斜率的Bresenham畫線算法

任務(wù)描述:

1.本關(guān)任務(wù)

(1)根據(jù)直線Bresenham算法補(bǔ)全line函數(shù)以繪制白色直線,其中直線斜率為任意情況。 (2)當(dāng)直線方程恰好經(jīng)過P(x,y)和T(x,y+1)的中點(diǎn)M時(shí),統(tǒng)一選取直線上方的T點(diǎn)為顯示的像素點(diǎn)。

2.輸入

代碼將自動(dòng)輸入一個(gè)OBJ三維人頭模型,具體模型如下圖:

計(jì)算機(jī)圖形學(xué)頭歌實(shí)訓(xùn)平臺(tái)答案——CG1-v2.0-直線繪制,計(jì)算機(jī)圖形學(xué)頭歌實(shí)訓(xùn)答案,頭歌作業(yè),算法,數(shù)據(jù)結(jié)構(gòu),c#,c語(yǔ)言,程序人生

3.輸出

若編寫的任意斜率的Bresenham畫線算法代碼正確,則程序會(huì)將模型轉(zhuǎn)換為線條圖片,具體結(jié)果如下圖所示:

計(jì)算機(jī)圖形學(xué)頭歌實(shí)訓(xùn)平臺(tái)答案——CG1-v2.0-直線繪制,計(jì)算機(jī)圖形學(xué)頭歌實(shí)訓(xùn)答案,頭歌作業(yè),算法,數(shù)據(jù)結(jié)構(gòu),c#,c語(yǔ)言,程序人生

整體代碼如下:

#include "tgaimage.h"
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include "model.h"
#include "geometry.h"

const TGAColor white = TGAColor(255, 255, 255, 255);
const TGAColor red = TGAColor(255, 0, 0, 255);
Model *model = NULL;
const int width = 800;
const int height = 800;

void line(int x0, int y0, int x1, int y1, TGAImage& image, TGAColor color)
{
    // Please add the code here
    /********** Begin ********/
    bool steep = false;
        if (abs(x0 - x1) < abs(y0 - y1))
        {
            std::swap(x0,y0);
            std::swap(x1,y1);
            steep = true;
        }
        if (x0 > x1)
        {
            std::swap(x0,x1);
            std::swap(y0,y1);
        }
        int dx = x1 - x0;
        int dy = abs(y1 - y0);
        int y = y0;
        int d = -dx;
        for(int x = x0;x <= x1;x++)
        {
            if(steep)
                image.set(y,x,color);
            else
                image.set(x,y,color);
            d = d + 2*dy;
            if(d >= 0)
            {
                y += (y1 > y0 ? 1:-1);
                d = d - 2*dx;
            }
        }


    /********** End *********/
}

int main(int argc, char** argv)
{
	model = new Model("african_head.obj");
	TGAImage image(width, height, TGAImage::RGB);
	for (int i = 0; i < model->nfaces(); i++) {
		std::vector<int> face = model->face(i);
		for (int j = 0; j < 3; j++) {
			Vec3f v0 = model->vert(face[j]);
			Vec3f v1 = model->vert(face[(j + 1) % 3]);
			int x0 = (v0.x + 1.)*width / 2.;
			int y0 = (v0.y + 1.)*height / 2.;
			int x1 = (v1.x + 1.)*width / 2.;
			int y1 = (v1.y + 1.)*height / 2.;
			line(x0, y0, x1, y1, image, white);
		}
	}
	image.flip_vertically(); // i want to have the origin at the left bottom corner of the image
	image.write_tga_file("../img_step3/test.tga");
	delete model;
	return 0;
}

同樣,小Mo還是會(huì)把需要填寫的代碼段po出來(lái)噠~

代碼段一:

? ? /********** Begin ********/

? ? bool steep = false;

? ? ? ? if (abs(x0 - x1) < abs(y0 - y1))

? ? ? ? {

? ? ? ? ? ? std::swap(x0,y0);

? ? ? ? ? ? std::swap(x1,y1);

? ? ? ? ? ? steep = true;

? ? ? ? }

? ? ? ? if (x0 > x1)

? ? ? ? {

? ? ? ? ? ? std::swap(x0,x1);

? ? ? ? ? ? std::swap(y0,y1);

? ? ? ? }

? ? ? ? int dx = x1 - x0;

? ? ? ? int dy = abs(y1 - y0);

? ? ? ? int y = y0;

? ? ? ? int d = -dx;

? ? ? ? for(int x = x0;x <= x1;x++)

? ? ? ? {

? ? ? ? ? ? if(steep)

? ? ? ? ? ? ? ? image.set(y,x,color);

? ? ? ? ? ? else

? ? ? ? ? ? ? ? image.set(x,y,color);

? ? ? ? ? ? d = d + 2*dy;

? ? ? ? ? ? if(d >= 0)

? ? ? ? ? ? {

? ? ? ? ? ? ? ? y += (y1 > y0 ? 1:-1);

? ? ? ? ? ? ? ? d = d - 2*dx;

? ? ? ? ? ? }

? ? ? ? }

? ? /********** End *********/

到了這里,關(guān)于計(jì)算機(jī)圖形學(xué)頭歌實(shí)訓(xùn)平臺(tái)答案——CG1-v2.0-直線繪制的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

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

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

相關(guān)文章

  • 【頭歌實(shí)訓(xùn)】kafka-入門篇

    【頭歌實(shí)訓(xùn)】kafka-入門篇

    本關(guān)任務(wù):使用 Kafka 命令創(chuàng)建一個(gè)副本數(shù)量為 1 、分區(qū)數(shù)量為 3 的 Topic 。 為了完成本關(guān)任務(wù),你需要掌握:1.如何使用 Kafka 的常用命令。 課程視頻《Kafka簡(jiǎn)介》 Kafka 簡(jiǎn)述 類 JMS 消息隊(duì)列,結(jié)合 JMS 中的兩種模式,可以有多個(gè)消費(fèi)者主動(dòng)拉取數(shù)據(jù),在 JMS 中只有點(diǎn)對(duì)點(diǎn)模式才

    2024年02月03日
    瀏覽(29)
  • 【頭歌實(shí)訓(xùn)】PySpark Streaming 入門

    【頭歌實(shí)訓(xùn)】PySpark Streaming 入門

    本關(guān)任務(wù):使用 Spark Streaming 實(shí)現(xiàn)詞頻統(tǒng)計(jì)。 為了完成本關(guān)任務(wù),你需要掌握: Spark Streaming 簡(jiǎn)介; Python 與 Spark Streaming; Python Spark Streaming API; Spark Streaming 初體驗(yàn)(套接字流)。 Spark Streaming 簡(jiǎn)介 Spark Streaming 是 Spark 的核心組件之一,為 Spark 提供了可拓展、高吞吐、容錯(cuò)的

    2024年02月04日
    瀏覽(71)
  • 獲取頭歌實(shí)訓(xùn)參考答案(EduCoder)

    頭歌EduCoder平臺(tái)實(shí)訓(xùn)答案在此,里面搜集了一些答案,可以查查有沒有想看的。 https://edaser.github.io/ 一定 不要直接復(fù)制答案 ,建議還是自己做,實(shí)在不會(huì)做的,參考看完后要獨(dú)立完成。 在這里可以查詢一些實(shí)訓(xùn)的答案,后臺(tái)的數(shù)據(jù)庫(kù)記錄了幾百個(gè)實(shí)訓(xùn)關(guān)卡的答案,實(shí)現(xiàn)的方

    2024年02月11日
    瀏覽(75)
  • 【頭歌實(shí)訓(xùn)】分布式文件系統(tǒng) HDFS

    【頭歌實(shí)訓(xùn)】分布式文件系統(tǒng) HDFS

    本關(guān)任務(wù):使用 Hadoop 命令來(lái)操作分布式文件系統(tǒng)。 為了完成本關(guān)任務(wù)你需要了解的知識(shí)有:1. HDFS 的設(shè)計(jì),2. HDFS 常用命令。 HDFS的設(shè)計(jì) 分布式文件系統(tǒng) 客戶:幫我保存一下這幾天的數(shù)據(jù)。 程序猿:好嘞,有多大呢? 客戶: 1T 。 程序猿:好沒問題,買個(gè)硬盤就搞定了。

    2024年04月15日
    瀏覽(27)
  • Educoder_頭歌實(shí)訓(xùn)_離散數(shù)學(xué)_圖論

    Educoder_頭歌實(shí)訓(xùn)_離散數(shù)學(xué)_圖論

    目錄 第1關(guān):圖的概念 任務(wù)描述 相關(guān)知識(shí) 圖的概念 習(xí)題參考 第2關(guān):圖的表示 任務(wù)描述 相關(guān)知識(shí) 圖的表示 編程要求 測(cè)試說(shuō)明 習(xí)題參考 第3關(guān):?jiǎn)卧醋疃掏穯栴} 任務(wù)描述 相關(guān)知識(shí) 單源最短通路 Dijkstra算法 編程要求 測(cè)試說(shuō)明 習(xí)題參考 本關(guān)任務(wù):學(xué)習(xí)圖的基本概念,完

    2024年02月03日
    瀏覽(34)
  • 數(shù)據(jù)庫(kù)原理 頭歌實(shí)訓(xùn) 數(shù)據(jù)庫(kù)常用對(duì)象

    任務(wù)描述 本關(guān)任務(wù):創(chuàng)建計(jì)算機(jī)系的學(xué)生信息的視圖 student_cs。 相關(guān)知識(shí) 行列子集視圖是指視圖的結(jié)果集來(lái)源于基本表,沒有經(jīng)過二次計(jì)算。 #####創(chuàng)建視圖 CREATE [OR REPLACE] [ALGORITHM = {UNDEFINED | MERGE | TEMPTABLE}] VIEW view_name [(column_list)] AS select_statement [WITH [CASCADED | LOCAL] CHECK OPTIO

    2024年02月04日
    瀏覽(29)
  • 【頭歌實(shí)訓(xùn)】Spark 完全分布式的安裝和部署

    掌握 Standalone 分布式集群搭建。 我們已經(jīng)掌握了 Spark 單機(jī)版安裝,那么分布式集群怎么搭建呢? 接下來(lái)我們學(xué)習(xí) Standalone 分布式集群搭建。 課程視頻 如果你需要在本地配置 Spark 完全分布式環(huán)境,可以通過查看課程視頻來(lái)學(xué)習(xí)。 課程視頻《克隆虛擬機(jī)與配置網(wǎng)絡(luò)》 課程視

    2024年02月04日
    瀏覽(27)
  • 湖南大學(xué)python頭歌實(shí)訓(xùn) 實(shí)驗(yàn)2:分支語(yǔ)句(一)

    湖南大學(xué)python頭歌實(shí)訓(xùn) 實(shí)驗(yàn)2:分支語(yǔ)句(一)

    第二章-Python語(yǔ)言基礎(chǔ)-2.1簡(jiǎn)單計(jì)算問題的求解(理科) 第1關(guān):數(shù)據(jù)輸入與輸出 編程要求 根據(jù)提示,在右側(cè)編輯器補(bǔ)充代碼,完成如下程序的編寫。 第一題 在屏幕上輸出字符串:hi, \\\"how are you\\\" ,I\\\'m fine and you 第二題 從鍵盤輸入兩個(gè)整數(shù),計(jì)算兩個(gè)數(shù)相除的商與余數(shù) 假設(shè)輸入

    2024年04月13日
    瀏覽(25)
  • 數(shù)字邏輯---頭歌實(shí)訓(xùn)作業(yè)---加法器設(shè)計(jì)(Logisim)

    數(shù)字邏輯---頭歌實(shí)訓(xùn)作業(yè)---加法器設(shè)計(jì)(Logisim)

    第1關(guān):半加器設(shè)計(jì) 如有任何不解或者想要答案代碼,可在評(píng)論區(qū)喊話我哦,希望我的答案對(duì)你有幫助,點(diǎn)個(gè)關(guān)注再走吧,感謝?。。?本關(guān)卡最終答案: ? 任務(wù)描述 本關(guān)任務(wù):利用在Logisim中的“組合邏輯分析”工具自動(dòng)生成半加器電路。 相關(guān)知識(shí) 半加器電路是指對(duì)兩個(gè)輸

    2023年04月13日
    瀏覽(28)

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

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請(qǐng)作者喝杯咖啡吧~博客贊助

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

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包