C# 三角関数

 課題

・イベント

・オーバーライド

UML(プリントアウト)

・指数

黄金比 (描写)

微分積分

フィボナッチ数列

・インベーダーベーム

RPG

・void think

 

そもそも、三角比とは。

 

直角三角形の

 

辺の長さ

面積

角度

 

を出力できる関数。

manapedia.jp

三角関数は、C# Systemclass の MathライブラリでOK

kuroeveryday.blogspot.jp

数学関数

System.Math クラスに、数学用の関数・定数などが定義されています。 表1に Math クラスのメンバーを示します(全て static)。

Math クラスのメンバー
  メンバー名意味
定数 PI 円周率。
E 自然対数の底
指数・対数関数 Exp(x) exp (x)
Pow(x, y) xy
Log(x) log e x
Log(x, y) log y x
Log10(x, y) log 10 x
三角関数 Sin(x) sin (x)
Cos(x) cos (x)
Tan(x) tan (x)
三角関数 Asin(x) sin −1 (x)
Acos(x) cos −1 (x)
Atan(x) tan −1 (x)
Atan2(y, x) tan −1 (
x
y
)
双曲線関数 Sinh(x) sinh (x)
Cosh(x) cosh (x)
Tanh(x) tanh (x)
整数化 Floor(x) x の床(x 以下の最大の整数)。
Ceiling(x) x の天井(x 以上の最小の整数)。
Round(x) x を四捨五入。
その他の数学関数 Abs(x) x の絶対値。
Sign(x) x 符号。x が正ならば1、負ならば-1、0ならば0。
Sqrt(x) x の平方根
最大・最小 Max(x, y) x, y のうち、大きい方を帰す。
Min(x, y) x, y のうち、小さい方を帰す。
その他 BigMul(x, y) int×intlongを帰す乗算を行う。
DivRem(x, y, out res) 商と剰余を同時に計算する。 res にx % yを代入し、x / yを帰す。
IEEERemainder(x, y) 剰余を計算する。x % yx - Math.Floor(x / y) * yなのに対して、 この関数はx - Math.Round(x / y) * yを帰す。

 

    class Program
    {
        static void Main(string args)
        {
            var angle = 30;
            var sin = Math.Sin(angle * (Math.PI / 180));
            var cos = Math.Cos(angle * (Math.PI / 180));
            var tan = Math.Tan(angle * (Math.PI / 180));

            Console.WriteLine("Sin {0}, Cos{1}, Tan:{2}",sin,cos,tan);

        }

 

cos_01.jpg

20100718seko.blog130.fc2.comusing System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            double x, z, a, angle;

            z = Double.Parse(textBox1.Text);
            a = Double.Parse(textBox2.Text);
            // Double 型に変換

            angle = Math.PI * a / 180.0;
            //円周率 × 角度

            x = z * Math.Cos(angle);
            textBox3.Text = x.ToString();
        }
    }
}

 

Math.PI は円周率

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string args)
        {
            var angle = 60;
            var cos = Math.Cos(angle * (Math.PI / 180));
            //Cosメソッド は ラジアン表記(Math.PI / 180)

            Console.WriteLine(cos);
        }
    }
}