2017年6月6日 星期二

Week16_吳宣旻

WEEK16  課堂der筆記筆記 


課堂作業1~~~Excel內插公式

1.


課堂作業2~~~內插公式

1.
#include <stdio.h>
FILE * fout=NULL;///存檔的步驟2, 宣告一個檔案的指標, (一開始是空的NULL)
void keyboard(unsigned char key,int x,int y)
{
    printf("%c\n", key);///你按了什麼鍵,印出來,方便了解老師按了什麼鍵
    if(key=='s'){///存檔的步驟3, 在按下 's' 鍵 save存檔
        if(fout == NULL){/// (一開始是空的NULL)
            fout = fopen("file.txt", "w+");///開啟檔案,檔名準備好, 並且是用 write加 模式
            printf("現在開啟一個檔案file.txt, w+模式\n");
        }
        printf("想要寫這些數值到檔案%f %f %f %f %f %f %f %f %f\n", angle[0], angle[1], angle[2], angle[3], angle[4], angle[5], angle[6], angle[7], angle[8]);
        fprintf( fout, "%f %f %f %f %f %f %f %f %f\n", angle[0], angle[1], angle[2], angle[3], angle[4], angle[5], angle[6], angle[7], angle[8]);
    }
    if(key=='0') now=0;
    if(key=='1') now=1;
    if(key=='2') now=2;
    if(key=='3') now=3;
    if(key=='4') now=4;
}





課堂作業3~~~內插公式

1.
#include <stdio.h>
FILE * fout=NULL;///存檔的步驟2, 宣告一個檔案的指標, (一開始是空的NULL)
FILE * fin=NULL;///讀檔的步驟1, 宣告一個檔案的指標, (一開始是空的NULL)
void keyboard(unsigned char key,int x,int y)
{
    printf("%c\n", key);///你按了什麼鍵,印出來,方便了解老師按了什麼鍵
    if(key=='s'){///存檔的步驟3, 在按下 's' 鍵 save存檔
        if(fout == NULL){/// (一開始是空的NULL)
            fout = fopen("file.txt", "w+");///開啟檔案,檔名準備好, 並且是用 write加 模式
            printf("現在開啟一個檔案file.txt, w+模式\n");
        }
        printf("想要寫這些數值到檔案%f %f %f %f %f %f %f %f %f\n", angle[0], angle[1], angle[2], angle[3], angle[4], angle[5], angle[6], angle[7], angle[8]);
        fprintf( fout, "%f %f %f %f %f %f %f %f %f\n", angle[0], angle[1], angle[2], angle[3], angle[4], angle[5], angle[6], angle[7], angle[8]);
    }
    if(key=='r'){///讀檔的步驟2, 按下 'r' 去read
        if(fin == NULL){
            fin = fopen("file.txt", "r");///讀檔的步驟3,檔名準備好, 並且是用 read 模式
            printf("Now open file.txt for read Mode\n");
        }
        fscanf(fin, "%f %f %f %f %f %f %f %f %f", &angle[0], &angle[1], &angle[2], &angle[3], &angle[4], &angle[5], &angle[6], &angle[7], &angle[8]);
        printf("Now read angle[] Pa Pa Pa\n");   ///讀檔的步驟 fscanf()讀進來
        glutPostRedisplay();
    }
    if(key=='0') now=0;
    if(key=='1') now=1;
    if(key=='2') now=2;
    if(key=='3') now=3;
    if(key=='4') now=4;
}




課堂作業4~~~內插公式

1. 連續
#include <stdio.h>
FILE * fout=NULL;///存檔的步驟2, 宣告一個檔案的指標, (一開始是空的NULL)
FILE * fin=NULL;///讀檔的步驟1, 宣告一個檔案的指標, (一開始是空的NULL)
void keyboard(unsigned char key,int x,int y)
{
    printf("%c\n", key);///你按了什麼鍵,印出來,方便了解老師按了什麼鍵
    if(key=='s'){///存檔的步驟3, 在按下 's' 鍵 save存檔
        if(fout == NULL){/// (一開始是空的NULL)
            fout = fopen("file.txt", "w+");///開啟檔案,檔名準備好, 並且是用 write加 模式
            printf("現在開啟一個檔案file.txt, w+模式\n");
        }
        printf("想要寫這些數值到檔案%f %f %f %f %f %f %f %f %f\n", angle[0], angle[1], angle[2], angle[3], angle[4], angle[5], angle[6], angle[7], angle[8]);
        fprintf( fout, "%f %f %f %f %f %f %f %f %f\n", angle[0], angle[1], angle[2], angle[3], angle[4], angle[5], angle[6], angle[7], angle[8]);
    }
    if(key=='r'){///讀檔的步驟2, 按下 'r' 去read
        if(fin == NULL){
            fin = fopen("file.txt", "r");///讀檔的步驟3,檔名準備好, 並且是用 read 模式
            printf("Now open file.txt for read Mode\n");
            fscanf(fin, "%f %f %f %f %f %f %f %f %f", &newAngle[0], &newAngle[1], &newAngle[2], &newAngle[3], &newAngle[4], &newAngle[5], &newAngle[6], &newAngle[7], &newAngle[8]);
        }
      //  fscanf(fin, "%f %f %f %f %f %f %f %f %f", &angle[0], &angle[1], &angle[2], &angle[3], &angle[4], &angle[5], &angle[6], &angle[7], &angle[8]);
    //    printf("Now read angle[] Pa Pa Pa\n");   ///讀檔的步驟 fscanf()讀進來
     //   glutPostRedisplay();
    }

    if(alpha >= 1.0){///如果讀太多,alpha超過了, 就要再讀新的angle, 而且要把原來新的,先變舊的
            /// oldAngle = newAngle
            for(int i=0;i<9;i++) oldAngle[i] = newAngle[i];
            /// read newAngle
            fscanf(fin, "%f %f %f %f %f %f %f %f %f", &newAngle[0], &newAngle[1], &newAngle[2], &newAngle[3], &newAngle[4], &newAngle[5], &newAngle[6], &newAngle[7], &newAngle[8]);
            printf("Now read angle[] Pa Pa Pa\n");   ///讀檔的步驟 fscanf()讀進來
            alpha=0.0;
        }

        ///angle = alpha * newAngle + (1-alpha)* oldAngle;
        for(int i=0;i<9;i++){///小心, 角度不見得只有9個,可能更多哦! 要調好,有更多,就要內插更多 ex. 20個
            angle[i]=alpha*newAngle[i] + (1-alpha)*oldAngle[i];///現在要改成交叉相乘的內插方式算角度
        }
        alpha += 0.1;///現在要改成交叉相乘的內插方式算角度, 每次加一點點alpha

        glutPostRedisplay();


    if(key=='0') now=0;
    if(key=='1') now=1;
    if(key=='2') now=2;
    if(key=='3') now=3;
    if(key=='4') now=4;
}




沒有留言:

張貼留言