By Unknown | Thursday, December 27, 2012
Posted in: , | 0 comments

Calculation dihedral angle from 2 vectors

計算acos的簡單範例,先用以下公式求出cos值,再利用acos得到角度





/* acos example */
#include <stdio.h>
#include <math.h>

#define PI 3.14159265

int main ()
{
  double param, result;
  param = 0.5;
  result = acos (param) * 180.0 / PI;
  printf ("The arc cosine of %lf is %lf degrees.\n", param, result );
  return 0;
}

參考

Read more
By Unknown | Wednesday, December 19, 2012
Posted in: , | 0 comments

Linked List

這個禮拜最令我傷神的,不過幸好很久以前有想過一次,所以要回復記憶比較沒有那麼困難。首先我先把C++版本的linked list刻出來,當然骨幹是參考別人的,然後自己有改了些東西,沒花多久時間很快就用出來了。

以下是標頭檔:

class CKLinkList{
    private:
        struct node {
            int x;
            int y;
            int z;
            node *link;
        } *p;

        int count_i;

    public:
        CKLinkList();
        void append(int);
        void insert_after(int,int);
        void insert_first(int);

        void display(void);
        void display_line(void);
        int length(void);
        void del(int);
        ~CKLinkList();
};

接下來是實作

#include <iostream>
#include "linklist.h"

using namespace std;

CKLinkList::CKLinkList(){
    p = NULL;
    count_i = 0;
};

int CKLinkList::length(){
    return count_i;
};

void CKLinkList::del(int num){
    node *q, *r;
    q = p;

    // No node
    if (p == NULL) return;

    // Delete the first node
    if (q->x == num){
        p = q->link;
        delete q;
        count_i--;
        return;
    }

    // Delete the remainder
    r = q;
    while( q != NULL){
        if (q->x == num){
            r->link = q->link;
            delete q;
            count_i--;
            return;
        }

        r = q;
        q = q->link;
    }
};

void CKLinkList::insert_first(int num){

    node *q, *t;
    q = p;

    t = new node;
    t->x = num;
    t->y = num*2;
    t->z = num*3;

    t->link = q;
    p = t;
    count_i++;
};

void CKLinkList::insert_after(int start_val,int num){
    node *q, *t;

    if (start_val != 0){
        q = p;
        while(q->link != NULL){
            if (q->x == start_val){

                t = new node;
                t->x = num;
                t->y = num*2;
                t->z = num*3;
                t->link = q->link;
                q->link = t;

                count_i++;
                return;
            }

            q = q->link;
        }
    }
};

void CKLinkList::append(int num){
    node *q, *t;

    if (p == NULL){
        p = new node;
        p->x = num;
        p->y = num*2;
        p->z = num*3;
        p->link = NULL;
    } else {
        q = p;
        while(q->link != NULL){
            q = q->link;
        }

        t = new node;
        t->x = num;
        t->y = num*2;
        t->z = num*3;
        t->link = NULL;
        q->link = t;
    }

    count_i++;
};

void CKLinkList::display_line(void){
    node *q;

    for(q = p; q != NULL; q = q->link){
        cout << " <- " << q->x;
    }

    cout << endl;
};

void CKLinkList::display(void){
    node *q;

    for(q = p; q != NULL; q = q->link){
        cout << "This is : " << q->x << ", " << q->y << ", " << q->z << endl;
    }
};

CKLinkList::~CKLinkList(){
    node *q;
    if (p == NULL) return;

    while (p != NULL){
        q = p->link;
        delete p;
        p = q;
    }
};

接下來我看到了一個使用C++ template去實作的版本,應該說是某個老師的教學課程(參考第10,11,12章),我就順便把她的課程講義看過一遍,然後把他的版本做出來。第一次使用C++的template,雖然滿麻煩的,但是真的是很強大,看來以後搞不好我的每個程式都要用template去做出來。以下是template的版本:

#include <iostream>
using namespace std;

template <class T>
class ChainNode {
    private:

    public:
        T data;
        ChainNode<T> *link;

        ChainNode(void){};
        ChainNode(const T& data){ this->data = data; };
        ChainNode(const T& data, ChainNode<T> *link){
            this->data = data;
            this->link = link;
        };
};

template <class T>
class Chain {
    private:
        ChainNode<T> *first;
        int count;

    public:
        Chain(void){ first = NULL; count = 0; };
        bool isEmpty() const {return first == NULL;}
        int IndexOf(const T&) const;
        int size(void){return count;}
        void Delete(int);
        void Insert(int,const T&);
        void Display(void);
        ~Chain();
};

// Destruction
template <class T>
Chain<T>::~Chain() {

    while (first != NULL){
        ChainNode<T> *next = first->link;
        delete first;
        first = next;
    }
};

template <class T>
int Chain<T>::IndexOf(const T& theElement) const{

    ChainNode<T> *currentNode = first;
    int index = 0;
    while(currentNode != NULL && currentNode->data != theElement){
        currentNode = currentNode->link;
        index++;
    }

    if (currentNode == NULL)
        return -1;
    else
        return index;
};

template <class T>
void Chain<T>::Delete(int theIndex){
    if (first == NULL) throw "Can not delete empty chain";

    ChainNode<T> *deleteNode;
    if (theIndex == 0){
        deleteNode = first;
        first = first->link;
        delete deleteNode;
        count--;

    } else {
        ChainNode<T> *p = first;
        for(int i =0; i< theIndex-1; i++){
            if (p == NULL) throw "Element not exist";
            p = p->link;
        }

        deleteNode = p->link;
        p->link = p->link->link;
        delete deleteNode;
        count--;
    }
}

template <class T>
void Chain<T>::Insert(int theIndex, const T& theElement){
    if (theIndex < 0) throw "Bad";

    if (theIndex == 0){
        first = new ChainNode<T>(theElement,first);
        count++;
    } else {
        ChainNode<T> *p = first;
        for(int i = 0; i < theIndex-1; i++){
            if (p == NULL) throw "Not Exist";
            p = p->link;
        }
        
        p->link = new ChainNode<T>(theElement, p->link);
        count++;
    }
};

template <class T>
void Chain<T>::Display(void){

    ChainNode<T> *p = first;

    while(p != NULL){
        cout << " <- " << p->data;
        p = p->link;
    }
    cout << endl;
};

int main() {
    cout << "This is LinkList .." << endl;

    Chain<int> *list = new Chain<int>;
    cout << "Size: " << list->size() << endl;

    list->Insert(0,1);
    list->Display();
    list->Insert(0,2);
    list->Display();
    list->Insert(1,3);
    list->Display();
    list->Insert(1,4);
    list->Display();
    list->Insert(0,5);
    list->Display();
    list->Delete(2);
    list->Display();

    cout << "Size: " << list->size() << endl;
}

繼續努力加油吧,這星期把linked list搞完之後還有很多要充實的,以上的source code都公布在github上看(其實blog根本不適合看這麼多程式碼是吧XD)。

Read more
By Unknown | Friday, December 14, 2012
Posted in: | 0 comments

Tempo Run

剛剛喵了一下我的跑步計畫,Tempo Run的配速看了之後覺得還有些不輕鬆。約8KM的距離速度在pace 5左右。根據最近這兩個禮拜在操場跑下來的結果,似乎400m@120s需要熱個將近10圈之後才有可能,所以我看短時間還是先把目標速訂在130s然後再慢慢加到120s。

Read more
By Unknown | Friday, December 14, 2012
Posted in: | 0 comments

Sublime 2快捷鍵

從網路上轉貼來的sublime2快捷鍵,我想我應該滿需要的

快捷鍵說明
Ctrl + X刪除一整行。(windows中會被剪下蓋掉,但是也可以用來快速把一行拿掉)
Ctrl + Enter在游標所在的那一行下方,插入一空白行。
(若只按Enter,游標後方若有字會被一併換到下行去)
Ctrl + Shift + Enter在游標所在的那一行上方,插入一空白行。
Ctrl +  Shift  + ↑將你游標所在那行往上搬移。
Ctrl +  Shift  + ↓將你游標所在那行往下搬移。
Ctrl + L選取游標所在的單行,當你連續按時,他會往下繼續選取。
Ctrl + D選取游標所在的單字,當你連續按時,他會選取在同個檔案裡面的相同字。
Ctrl + M跑到離自己最近的父母去。(例如大/小括號{},())
Ctrl + Shift + M選取同父母的其他行。(例如大/小括號{},())
Ctrl + KK刪除游標所在那行後面的文字。
Ctrl + K + ⌫刪除游標所在那行前面的文字。
Ctrl + ]往後縮排。
Ctrl + [往前縮排。
Ctrl + Shift + D複製游標所在那行,並且貼在該行下方。
Ctrl + J將游標所在的下一行,加入到游標所在的行數最後方。
Ctrl + /單行註解/解除註解( // )
Ctrl +  Shift  + /區域註解( /**/)
Ctrl + Y重複上次的動作
Ctrl +  Shift  + V跟Ctrl+V的差別在於,此快捷鍵會將你的paste的字,自動作縮牌動作。
Ctrl + Uundo功能,跟Ctrl+Z的差別在於,此快捷鍵會先前去到你上次所變更的行數,當你續按的時候才會將他undo。

快捷鍵說明
Ctrl + P用名字快速打開檔案。
Ctrl + R用名字快速找到function或標籤(ex:html的id)。
Ctrl + ;在該檔案找最接近的字。                                                                            
Ctrl + G在該檔案前往該行。
Ctrl +  Shift  + P命令提示
Ctrl + KB隱藏會顯示side bar
Ctrl + F尋找該檔案裡的字
Ctrl + H 替換字
Ctrl +  Shift  + F尋找所有檔案裡的字 
Ctrl + Shift + t開啟上次關閉的檔案
Ctrl + PgUp在檔案視窗中切換(往上一個檔案)
Ctrl + PgDn在檔案視窗中切換(往下一個檔案)
Ctrl + ⇆在檔案視窗中切換   

Read more
By Unknown | Tuesday, November 20, 2012
Posted in: | 0 comments

2012-12月訓練計畫

以下根據Runners world的smart coach給出來的課表,目標是在12/31達到半馬1:50

WEEK 1: 27 KM
Tue Nov 27 Easy Run Dist: 3 KM @6:02
Thu Nov 29 Tempo Run Dist: 8 KM, inc Warm; 5 KM @ 5:05; Cool
Fri Nov 30 Easy Run Dist: 3 KM @6:02
Sun Dec 2 Long Run Dist: 13 KM @6:02

WEEK 2: 27 KM
Tue Dec 4 Easy Run Dist: 4 KM @6:01
Thu Dec 6 Speedwork Dist: 7 KM, inc Warm; 2x1600 in 7:41 w/800 jogs; Cool
Fri Dec 7 Easy Run Dist: 3 KM @6:01
Sun Dec 9 Long Run Dist: 13 KM @6:01

WEEK 3: 29 KM
Tue Dec 11 Easy Run Dist: 4 KM @6:00
Thu Dec 13 Tempo Run Dist: 8 KM, inc Warm; 5 KM @ 5:03; Cool
Fri Dec 14 Easy Run Dist: 3 KM @6:00
Sun Dec 16 Long Run Dist: 14 KM @6:00

WEEK 4: 30 KM
Tue Dec 18 Easy Run Dist: 3 KM @5:58
Thu Dec 20 Tempo Run Dist: 8 KM, inc Warm; 5 KM @ 5:02; Cool
Fri Dec 21 Easy Run Dist: 3 KM @5:58
Sun Dec 23 Long Run Dist: 16 KM @5:58

WEEK 5: 20 KM
Tue Dec 25 Easy Run Dist: 5 KM @5:57
Wed Dec 26 Easy Run Dist: 5 KM @5:57
Thu Dec 27 Speedwork Dist: 5 KM, inc Warm; 1x1600 in 7:37 w/800 jogs; Cool
Sat Dec 29 Easy Run Dist: 5 KM @5:57

WEEK 6: 21 KM
Mon Dec 31 Half Marathon Race Day 21.1 KM @5:10 Time: 1:49:01

Read more
By Unknown | Saturday, November 17, 2012
Posted in: | 0 comments

Note of Aircraft System

Superchargers and Turbosuperchargers

Differnce

Supercharger relies on engine-driven air pump or compressor, turbosupercharger use engine exhaust streams run through turbine and then spin the compressor.

Turbochargers

Cons
  1. Most efficient way to increase horsepower.
  2. Engine horsepower don't decrease is avoided.
  3. Ability to maintain control over engine's horsepower from sea level to critical altitude.
Elements
  1. Compressor
  2. turbine
Since the temperature of gas rises whiling it compresses, many turbocharger use intercooler to decrease it to avoid detonation.


Ignition System

Read more
By Unknown | Friday, November 02, 2012
Posted in: | 0 comments

Git投影片

以下內容來自ihower,把它收集起來以後可以慢慢看。


Read more