鵺鳥鳴く

『だが、やるなら全力をそれに注ぎたまえ』――J.D.サリンジャー

全体表示

[ リスト ]

C言語 内積とかcosθの値とか

#include <stdio.h>
#include <math.h>


typedef struct _POINT
{
float x, y;
}POINT;

float PointToLength(POINT* pt)
{
return sqrt((pt->x * pt->x) + (pt->y * pt->y));
}

float DotProduct(POINT* pt1, POINT* pt2)
{
return pt1->x * pt2->x + pt1->y * pt2->y;
}

float VecToDegree(POINT* pt1, POINT* pt2)
{
return DotProduct(pt1, pt2) / (PointToLength(pt1) * PointToLength(pt2));
}


int main()
{
POINT pt1, pt2;
printf("1点目の入力:");
scanf("%f %f", &pt1.x, &pt1.y);
printf("2点目の入力:");
scanf("%f %f", &pt2.x, &pt2.y);

printf("1点目の長さ:%f\n", PointToLength(&pt1));
printf("2点目の長さ:%f\n", PointToLength(&pt2));
printf("内積の値:%f\n", DotProduct(&pt1, &pt2));
printf("cosθの値:%f\n", VecToDegree(&pt1, &pt2));

return 0;
}

cosθの値はでるけど、θそのものの出し方は知らん。
θを使った何らかの式がありさえすれば式変形で出せるんだろうがな。

閉じる コメント(2)

顔アイコン

atan2()(だっけ)を調べてみるのが吉かと

2008/12/31(水) 午後 10:43 Classiclll

顔アイコン

なるほど、米ありがとうございます

2009/1/5(月) 午後 2:44 [ GRGSIBERIA ]

コメント投稿
名前パスワードブログ
投稿

閉じる トラックバック(0)

トラックバックされた記事

トラックバックされている記事がありません。

トラックバック先の記事

  • トラックバック先の記事がありません。

芸能人・有名人の新着記事

Yahoo Image
あべこうじ
ラフブロ
05月30日 01:54

.
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31

GRGSIBERIA
人気度

ヘルプ

Yahoo Image

  今日 全体
訪問者 8 88130
ブログリンク 0 7
コメント 0 152
トラックバック 0 34
検索 検索

開設日: 2006/5/29(月)


プライバシーポリシー -  利用規約 -  ガイドライン -  順守事項 -  ヘルプ・お問い合わせ

Copyright (C) 2012 Yahoo Japan Corporation. All Rights Reserved.