日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

C语言模拟质点运动轨迹坐标,C语言定时器的使用 计算质点运动的移位

發(fā)布時(shí)間:2024/10/5 编程问答 34 豆豆
生活随笔 收集整理的這篇文章主要介紹了 C语言模拟质点运动轨迹坐标,C语言定时器的使用 计算质点运动的移位 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

C語言定時(shí)器的使用 計(jì)算質(zhì)點(diǎn)運(yùn)動(dòng)的位移

用C語言編一個(gè)質(zhì)點(diǎn)運(yùn)動(dòng)的程序,知道起始點(diǎn)坐標(biāo)(x1,y1)和終止點(diǎn)坐標(biāo)(x2,y2),速度v和加速度a也知道,現(xiàn)在就想通過計(jì)算每隔一個(gè)時(shí)間t(假設(shè)10毫秒)質(zhì)點(diǎn)的位移而得知質(zhì)點(diǎn)所在的坐標(biāo)(x,y)。

應(yīng)該是要用定時(shí)器吧,但是我不會(huì)用,網(wǎng)上一查定時(shí)器都是單片機(jī)的定時(shí)器,但我不用單片器,只是單純的計(jì)算。。有沒有大神可以幫我編寫這一段程序,萬分感謝

------解決思路----------------------

你可以使用?alarm()??ualarm()??的信號(hào)機(jī)制。?在SIGALRM?信號(hào)捕捉函數(shù)中處理你的邏輯

------解決思路----------------------

為什么不用

BOOL?LineDDA(

int?nXStart,?????????????//?x-coordinate?of?line's?starting?point

int?nYStart,?????????????//?y-coordinate?of?line's?starting?point

int?nXEnd,???????????????//?x-coordinate?of?line's?ending?point

int?nYEnd,???????????????//?y-coordinate?of?line's?ending?point

LINEDDAPROC?lpLineFunc,??//?pointer?to?callback?function

LPARAM?lpData????????????//?pointer?to?application-defined?data

);

呢?

------解決思路----------------------

參考下面:#pragma?comment(lib,"user32")

#include?

#include?

#include?

#include?

char?datestr[16];

char?timestr[16];

char?mss[4];

void?log(char?*s)?{

struct?tm?*now;

struct?timeb?tb;

ftime(&tb);

now=localtime(&tb.time);

sprintf(datestr,"%04d-%02d-%02d",now->tm_year+1900,now->tm_mon+1,now->tm_mday);

sprintf(timestr,"%02d:%02d:%02d",now->tm_hour?????,now->tm_min??,now->tm_sec?);

sprintf(mss,"%03d",tb.millitm);

printf("%s?%s.%s?%s",datestr,timestr,mss,s);

}

VOID?CALLBACK?myTimerProc1(

HWND?hwnd,?//?handle?of?window?for?timer?messages

UINT?uMsg,?//?WM_TIMER?message

UINT?idEvent,?//?timer?identifier

DWORD?dwTime?//?current?system?time

)?{

log("In?myTimerProc1\n");

}

VOID?CALLBACK?myTimerProc2(

HWND?hwnd,?//?handle?of?window?for?timer?messages

UINT?uMsg,?//?WM_TIMER?message

UINT?idEvent,?//?timer?identifier

DWORD?dwTime?//?current?system?time

)?{

log("In?myTimerProc2\n");

}

int?main()?{

int?i;

MSG?msg;

SetTimer(NULL,0,1000,myTimerProc1);

SetTimer(NULL,0,2000,myTimerProc2);

for?(i=0;i<20;i++)?{

Sleep(500);

log("In?main\n");

if?(GetMessage(&msg,NULL,0,0))?{

TranslateMessage(&msg);

DispatchMessage(&msg);

}

}

return?0;

}

//2012-07-26?17:29:06.375?In?main

//2012-07-26?17:29:06.875?In?myTimerProc1

//2012-07-26?17:29:07.375?In?main

//2012-07-26?17:29:07.875?In?myTimerProc2

//2012-07-26?17:29:08.375?In?main

//2012-07-26?17:29:08.375?In?myTimerProc1

//2012-07-26?17:29:08.875?In?main

//2012-07-26?17:29:08.875?In?myTimerProc1

//2012-07-26?17:29:09.375?In?main

//2012-07-26?17:29:09.890?In?myTimerProc2

//2012-07-26?17:29:10.390?In?main

//2012-07-26?17:29:10.390?In?myTimerProc1

//2012-07-26?17:29:10.890?In?main

//2012-07-26?17:29:10.890?In?myTimerProc1

//2012-07-26?17:29:11.390?In?main

//2012-07-26?17:29:11.890?In?myTimerProc2

//2012-07-26?17:29:12.390?In?main

//2012-07-26?17:29:12.390?In?myTimerProc1

//2012-07-26?17:29:12.890?In?main

//2012-07-26?17:29:12.890?In?myTimerProc1

//2012-07-26?17:29:13.390?In?main

//2012-07-26?17:29:13.890?In?myTimerProc2

//2012-07-26?17:29:14.390?In?main

//2012-07-26?17:29:14.390?In?myTimerProc1

//2012-07-26?17:29:14.890?In?main

//2012-07-26?17:29:14.890?In?myTimerProc1

//2012-07-26?17:29:15.390?In?main

//2012-07-26?17:29:15.890?In?myTimerProc2

//2012-07-26?17:29:16.390?In?main

//2012-07-26?17:29:16.390?In?myTimerProc1

//2012-07-26?17:29:16.890?In?main

//2012-07-26?17:29:16.890?In?myTimerProc1

//2012-07-26?17:29:17.390?In?main

//2012-07-26?17:29:17.890?In?myTimerProc2

//2012-07-26?17:29:18.390?In?main

//2012-07-26?17:29:18.390?In?myTimerProc1

//2012-07-26?17:29:18.890?In?main

//2012-07-26?17:29:18.890?In?myTimerProc1

//2012-07-26?17:29:19.390?In?main

//2012-07-26?17:29:19.890?In?myTimerProc2

和下面:#include?

#include?

#include?

#ifdef?WIN32

#include?

#include?

#include?

#define??MYVOID?????????????void

#else

#include?

#include?

#include?

#define??CRITICAL_SECTION???pthread_mutex_t

#define??_vsnprintf?????????vsnprintf

#define??MYVOID?????????????void?*

#endif

//Log{

#define?MAXLOGSIZE?20000000

#define?ARRSIZE(x)?(sizeof(x)/sizeof(x[0]))

#include?

#include?

#include?

char?logfilename1[]="MyLog1.log";

char?logfilename2[]="MyLog2.log";

char?logstr[16000];

char?datestr[16];

char?timestr[16];

char?mss[4];

CRITICAL_SECTION?cs_log;

FILE?*flog;

#ifdef?WIN32

void?Lock(CRITICAL_SECTION?*l)?{

EnterCriticalSection(l);

}

void?Unlock(CRITICAL_SECTION?*l)?{

LeaveCriticalSection(l);

}

void?sleep_ms(int?ms)?{

Sleep(ms);

}

#else

void?Lock(CRITICAL_SECTION?*l)?{

pthread_mutex_lock(l);

}

void?Unlock(CRITICAL_SECTION?*l)?{

pthread_mutex_unlock(l);

}

void?sleep_ms(int?ms)?{

usleep(ms*1000);

}

#endif

void?LogV(const?char?*pszFmt,va_list?argp)?{

struct?tm?*now;

struct?timeb?tb;

if?(NULL==pszFmt

------解決思路----------------------

0==pszFmt[0])?return;

if?(-1==_vsnprintf(logstr,ARRSIZE(logstr),pszFmt,argp))?logstr[ARRSIZE(logstr)-1]=0;

ftime(&tb);

now=localtime(&tb.time);

sprintf(datestr,"%04d-%02d-%02d",now->tm_year+1900,now->tm_mon+1,now->tm_mday);

sprintf(timestr,"%02d:%02d:%02d",now->tm_hour?????,now->tm_min??,now->tm_sec?);

sprintf(mss,"%03d",tb.millitm);

printf("%s?%s.%s?%s",datestr,timestr,mss,logstr);

flog=fopen(logfilename1,"a");

if?(NULL!=flog)?{

fprintf(flog,"%s?%s.%s?%s",datestr,timestr,mss,logstr);

if?(ftell(flog)>MAXLOGSIZE)?{

fclose(flog);

if?(rename(logfilename1,logfilename2))?{

remove(logfilename2);

rename(logfilename1,logfilename2);

}

flog=fopen(logfilename1,"a");

if?(NULL==flog)?return;

}

fclose(flog);

}

}

void?Log(const?char?*pszFmt,...)?{

va_list?argp;

Lock(&cs_log);

va_start(argp,pszFmt);

LogV(pszFmt,argp);

va_end(argp);

Unlock(&cs_log);

}

//Log}

int?No_Loop=0;

MYVOID?testThread(void?*pcn)?{

int?n,i;

n=(int)pcn;

i=0;

while?(1)?{

sleep_ms(1000);

Log("in?testThread?%d:i==%ds\n",n,++i);

if?(i>=5)?No_Loop=1;

}

}

int?main(int?argc,char?*?argv[])?{

int?i;

#ifdef?WIN32

InitializeCriticalSection(&cs_log);

#else

pthread_mutex_init(&cs_log,NULL);

pthread_t?threads[1];

int?threadsN;

int?rc;

#endif

Log("=========BEGIN==================\n");

#ifdef?WIN32

_beginthread((void(__cdecl?*)(void?*))testThread,0,(void?*)1);

#else

threadsN=0;

rc=pthread_create(&(threads[threadsN++]),NULL,testThread,(void?*)1);if?(rc)?Log("%d=pthread_create?%d?error!\n",rc,threadsN-1);

#endif

i=0;

while?(1)?{

sleep_ms(100);

Log("in?main:i==%d\n",++i);

if?(No_Loop==1)?break;//

}

Log("=========END====================\n");

#ifdef?WIN32

DeleteCriticalSection(&cs_log);

#else

pthread_mutex_destroy(&cs_log);

#endif

return?0;

}

//2012-06-14?16:27:21.500?=========BEGIN==================

//2012-06-14?16:27:21.609?in?main:i==1

//2012-06-14?16:27:21.718?in?main:i==2

//2012-06-14?16:27:21.828?in?main:i==3

//2012-06-14?16:27:21.937?in?main:i==4

//2012-06-14?16:27:22.046?in?main:i==5

//2012-06-14?16:27:22.156?in?main:i==6

//2012-06-14?16:27:22.265?in?main:i==7

//2012-06-14?16:27:22.375?in?main:i==8

//2012-06-14?16:27:22.484?in?main:i==9

//2012-06-14?16:27:22.500?in?testThread?1:i==1s

//2012-06-14?16:27:22.593?in?main:i==10

//2012-06-14?16:27:22.703?in?main:i==11

//2012-06-14?16:27:22.812?in?main:i==12

//2012-06-14?16:27:22.921?in?main:i==13

//2012-06-14?16:27:23.031?in?main:i==14

//2012-06-14?16:27:23.140?in?main:i==15

//2012-06-14?16:27:23.250?in?main:i==16

//2012-06-14?16:27:23.359?in?main:i==17

//2012-06-14?16:27:23.468?in?main:i==18

//2012-06-14?16:27:23.500?in?testThread?1:i==2s

//2012-06-14?16:27:23.578?in?main:i==19

//2012-06-14?16:27:23.687?in?main:i==20

//2012-06-14?16:27:23.796?in?main:i==21

//2012-06-14?16:27:23.906?in?main:i==22

//2012-06-14?16:27:24.015?in?main:i==23

//2012-06-14?16:27:24.125?in?main:i==24

//2012-06-14?16:27:24.234?in?main:i==25

//2012-06-14?16:27:24.343?in?main:i==26

//2012-06-14?16:27:24.453?in?main:i==27

//2012-06-14?16:27:24.500?in?testThread?1:i==3s

//2012-06-14?16:27:24.562?in?main:i==28

//2012-06-14?16:27:24.671?in?main:i==29

//2012-06-14?16:27:24.781?in?main:i==30

//2012-06-14?16:27:24.890?in?main:i==31

//2012-06-14?16:27:25.000?in?main:i==32

//2012-06-14?16:27:25.109?in?main:i==33

//2012-06-14?16:27:25.218?in?main:i==34

//2012-06-14?16:27:25.328?in?main:i==35

//2012-06-14?16:27:25.437?in?main:i==36

//2012-06-14?16:27:25.500?in?testThread?1:i==4s

//2012-06-14?16:27:25.546?in?main:i==37

//2012-06-14?16:27:25.656?in?main:i==38

//2012-06-14?16:27:25.765?in?main:i==39

//2012-06-14?16:27:25.875?in?main:i==40

//2012-06-14?16:27:25.984?in?main:i==41

//2012-06-14?16:27:26.093?in?main:i==42

//2012-06-14?16:27:26.203?in?main:i==43

//2012-06-14?16:27:26.312?in?main:i==44

//2012-06-14?16:27:26.421?in?main:i==45

//2012-06-14?16:27:26.500?in?testThread?1:i==5s

//2012-06-14?16:27:26.531?in?main:i==46

//2012-06-14?16:27:26.531?=========END====================

總結(jié)

以上是生活随笔為你收集整理的C语言模拟质点运动轨迹坐标,C语言定时器的使用 计算质点运动的移位的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 亚洲欧美在线免费观看 | 天天做天天射 | 国产色图视频 | 青青操在线视频 | 亚洲高清在线播放 | 亚洲免费观看高清完整 | 爱爱三级视频 | 麻豆av网址| 欧美性天堂 | 成人国产一区二区三区精品麻豆 | www.婷婷 | 在线国产一区二区 | 欧美狂猛xxxxx乱大交3 | 国产精品中文在线 | 日韩在线一二三 | 亚洲久草视频 | 青青草福利 | 国产精欧美一区二区三区白种人 | 快色视频在线观看 | 国产视频在 | 三级黄毛片 | 久久久av免费 | 国产传媒欧美日韩 | 国产精品乱码一区二区视频 | 午夜嘿嘿嘿 | 熟女性饥渴一区二区三区 | 成人天堂网 | 亚洲一区二区小说 | 国产一区二区三区免费视频 | 午夜影视福利 | 中文字幕国产专区 | 中日韩午夜理伦电影免费 | 色一情| 国产成人精品一区二区色戒 | www99热| 99久久精品免费视频 | 日韩蜜桃视频 | 亚洲国产精品激情在线观看 | 久久久久国产精品无码免费看 | 日韩欧美国产片 | 婷婷综合五月 | 天天躁日日躁狠狠躁av麻豆 | 一本久道久久综合 | 亚洲黄在线观看 | 给我看高清的视频在线观看 | 久久久青青 | 高跟肉丝丝袜呻吟啪啪网站av | 欧美午夜不卡 | av播放网站 | 在线免费看av网站 | 日韩欧美一区二区三区四区五区 | 打开每日更新在线观看 | 成人午夜毛片 | 少妇一级淫片免费放 | 成人精品 | 交视频在线播放 | 又大又硬又爽免费视频 | 制服丝袜在线播放 | 国产精品亚洲一区二区三区 | 欧美老肥妇做.爰bbww视频 | 黑人玩弄人妻一区二区绿帽子 | 国产清纯在线 | 开心激情久久 | 亚洲第一天堂av | 亚洲精品www久久久久久 | 三年中文免费观看大全动漫 | 欧美 亚洲 另类 偷偷 自拍 | 91深夜视频 | 国产在线传媒 | 幸福宝在线观看 | 校园春色欧美 | 久久久久久一区二区 | 欧美乱轮 | 日本成人动漫在线观看 | 久久一级黄色片 | 国产农村妇女毛片精品久久 | 国产美女又黄又爽又色视频免费 | h片在线观看网站 | 日韩最新在线 | 日本欧美色 | 日韩欧美一区视频 | 动漫精品一区一码二码三码四码 | 综合免费视频 | 亚洲欧美强伦一区二区 | japanese国产| 无码人妻久久一区二区三区不卡 | 自拍视频啪 | 国产夫妇交换聚会群4p | 午夜性剧场 | 黄色大片网站在线观看 | 51免费看成人啪啪片 | 熟女高潮一区二区三区视频 | 亚洲av区无码字幕中文色 | 国产做爰免费观看 | 麻豆日产六区 | 亚洲成人另类 | 国产色频| 日韩av成人在线观看 | 亚洲尤物视频 |