龍神録プログラミングの館の第34章のポインタについて
Posted: 2012年8月01日(水) 18:58
現在、龍神録プログラミングの館の第34章を見ているのですが分からないところがあります。
この引数に使用されたポインタについて調べたのですが仕組みが理解できません。
あとその仕組みを利用した結果「cp,p,c,cq,q」には何が入るのかを教えて欲しいです。お願いします。
/* 2次元ベクトル */
typedef struct {
double x, y;
} Vector2_t;
/* diff ← ベクトル p - q */
void Vector2Diff(Vector2_t *diff, const Vector2_t *p, const Vector2_t *q)
{
diff->x = p->x - q->x;
diff->y = p->y - q->y;
}
/* ベクトル p と q の内積 */
double Vector2InnerProduct(const Vector2_t *p, const Vector2_t *q)
{
return p->x * q->x + p->y * q->y;
}
/* ベクトル p と q の外積 */
double Vector2OuterProduct(const Vector2_t *p, const Vector2_t *q)
{
return p->x * q->y - p->y * q->x;
}
/*中略*/
/* ベクトル C→P と C→Q のなす角θおよび回転方向を求める.*/
Vector2_t c, p, q; /* 入力データ */
Vector2_t cp; /* ベクトル C→P */
Vector2_t cq; /* ベクトル C→Q */
double s; /* 外積:(C→P) × (C→Q) */
double t; /* 内積:(C→P) ・ (C→Q) */
double theta,theta2;/* θ (ラジアン) */
/* c,p,q を所望の値に設定する.*/
c.x = pt[0].x; c.y = pt[0].y;
p.x = pt[1].x; p.y = pt[1].y;
q.x = x; q.y = y;
/* 回転方向および角度θを計算する.*/
Vector2Diff(&cp, &p, &c); /* cp ← p - c */
Vector2Diff(&cq, &q, &c); /* cq ← q - c */
s = Vector2OuterProduct(&cp, &cq); /* s ← cp × cq */
t = Vector2InnerProduct(&cp, &cq); /* t ← cp ・ cq */
theta = atan2(s, t);
あとその仕組みを利用した結果「cp,p,c,cq,q」には何が入るのかを教えて欲しいです。お願いします。