c語(yǔ)言打印貝塞爾曲線坐標(biāo)(三階)

貝塞爾曲線

貝塞爾曲線(Bézier curve),是應(yīng)用于二維圖形應(yīng)用程序的數(shù)學(xué)曲線。一般的矢量圖形軟件通過(guò)它來(lái)精確畫(huà)出曲線,貝賽爾曲線由線段節(jié)點(diǎn)組成,節(jié)點(diǎn)是可拖動(dòng)的支點(diǎn),線段像可伸縮的皮筋,我們?cè)诶L圖工具上看到的鋼筆工具就是來(lái)做這種矢量曲線的。貝塞爾曲線是計(jì)算機(jī)圖形學(xué)中相當(dāng)重要的參數(shù)曲線,在一些比較成熟的位圖軟件中也有貝塞爾曲線工具,如PhotoShop等,模擬鼠標(biāo)移動(dòng)軌跡過(guò)驗(yàn)證碼的時(shí)候也會(huì)用到。


屁話不多說(shuō) 直接上代碼鴨!

控制點(diǎn)控制曲線

#include<stdio.h>

typedef struct Point

{

? ? int x;

? ? int y;

}Point;

int main()

{

? ? Point p0, p1, p2, p3 ,pot;//起始點(diǎn) 控制點(diǎn)1 控制點(diǎn)2 終止點(diǎn)3 繪制點(diǎn)

? ? float k,b;//斜率 和 截距

? ? p0.x = 100;//比如這是起始點(diǎn)x

? ? p0.y = 400;//比如這是起始點(diǎn)y

? ? p1.x = 100;//控制點(diǎn)坐標(biāo)可以隨便整數(shù)

? ? p1.y = 800;//控制點(diǎn)坐標(biāo)可以隨便整數(shù)

? ? p2.x = 800;//控制點(diǎn)坐標(biāo)可以隨便整數(shù)

? ? p2.y = 100;//控制點(diǎn)坐標(biāo)可以隨便整數(shù)

? ? p3.x = 1100;//比如這是起終點(diǎn)x

? ? p3.y = 600;//比如這是起終點(diǎn)y

? ? printf("打印控制點(diǎn)坐標(biāo)p1=%d,%d? ? p2=%d,%d\n",p1.x,p1.y,p2.x,p2.y);

? ? float? t = 0.01;//曲線參數(shù)t

? ? float temp = 1 - t;

? ? printf("輸出軌跡\nx = [");

? ? for(t=0;t<1;t+=0.01)

? ? {

? ? ? ? temp = 1 - t;

? ? ? ? pot.x = p0.x * temp * temp * temp + 3 * p1.x * t * temp * temp + 3 * p2.x * t * t * temp + p3.x * t * t * t;

? ? ? ? printf("%d,",pot.x);

? ? }

? ? printf("]\ny = [");

? ? for(t=0;t<1;t+=0.01)

? ? {

? ? ? ? temp = 1 - t;

? ? ? ? pot.y = p0.y * temp * temp * temp + 3 * p1.y * t * temp * temp + 3 * p2.y * t * t * temp + p3.y * t * t * t;

? ? ? ? printf("%d,",pot.y);

? ? }

? ? printf("]\n");

? ? return 0;

}



還有模擬鼠標(biāo)行為的軌跡代碼 每次坐標(biāo)會(huì)不一樣

/*

? ? 模擬鼠標(biāo)移動(dòng)軌跡

*/

#include<stdio.h>/

#include<stdlib.h>

#include<time.h>

typedef struct Point

{

? ? int x;

? ? int y;

}Point;

int main()

{

? ? srand(time(NULL));

? ? Point p0, p1, p2, p3 ,pot;//起始點(diǎn) 控制點(diǎn)1 控制點(diǎn)2 終止點(diǎn)3 繪制點(diǎn)

? ? float k,b;//斜率 和 截距

? ? p0.x = 100;//比如這是起始點(diǎn)x

? ? p0.y = 400;//比如這是起始點(diǎn)y

? ? p1.x = rand()%1399;//控制點(diǎn)坐標(biāo)可以隨便整數(shù)

? ? p1.y = -1;//控制點(diǎn)坐標(biāo)可以隨便整數(shù)

? ? p2.x = rand()%1399;//控制點(diǎn)坐標(biāo)可以隨便整數(shù)

? ? p2.y=-1;//控制點(diǎn)坐標(biāo)可以隨便整數(shù)

? ? p3.x = 1100;//比如這是起終點(diǎn)x

? ? p3.y = 600;//比如這是起終點(diǎn)y

? ? k = (p3.y*1.0-p0.y*1.0)/(p3.x*1.0-p0.x*1.0);

? ? b = p0.y*1.0 - k * p0.x*1.0;

? ? //printf("k,b = %f, %f\n",k,b);

? ? while(p1.y>1399 || p1.y<0){//改變控制點(diǎn)的y值不要偏的太離譜 可以改動(dòng)300越小波動(dòng)越小

? ? ? ? p1.y = k*p1.x*1.0+b+(rand()%300-150)*1.0;

? ? ? ? //printf("打印控制點(diǎn)坐標(biāo)p1.x = %d? p1.y = %d %f \n",p1.x,p1.y,k*p1.x*1.0+b);

? ? }

? ? while(p2.y>1399 || p2.y<0){

? ? ? ? p2.y = k*p2.x*1.0+b+(rand()%300-150)*1.0;

? ? ? ? //printf("p2.x = %d? p2.y = %d %f \n",p2.x,p2.y,k*p1.x*1.0+b);

? ? }

? ? printf("打印控制點(diǎn)坐標(biāo)p1=%d,%d? ? p2=%d,%d\n",p1.x,p1.y,p2.x,p2.y);

? ? float? t = 0.01;//曲線參數(shù)t

? ? float temp = 1 - t;

? ? printf("輸出軌跡\nx = [");

? ? for(t=0;t<1;t+=0.01)

? ? {

? ? ? ? temp = 1 - t;

? ? ? ? pot.x = p0.x * temp * temp * temp + 3 * p1.x * t * temp * temp + 3 * p2.x * t * t * temp + p3.x * t * t * t;

? ? ? ? printf("%d,",pot.x);

? ? }

? ? printf("]\ny = [");

? ? for(t=0;t<1;t+=0.01)

? ? {

? ? ? ? temp = 1 - t;

? ? ? ? pot.y = p0.y * temp * temp * temp + 3 * p1.y * t * temp * temp + 3 * p2.y * t * t * temp + p3.y * t * t * t;

? ? ? ? printf("%d,",pot.y);

? ? }

? ? printf("]\n");

? ? return 0;

}

還有

圖用python畫(huà)了 ,c語(yǔ)言太麻煩了 就直接打印坐標(biāo)啦 湊活看吧 嘻嘻嘻 不服來(lái)找我?我家住番斗大街番斗花園2號(hào)樓1001室,?我爸叫胡英俊,我媽叫張小麗,?我叫胡圖圖

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容