Shall We Live in a Castle?

自分へ あなたへ

回転行列 任意点から ホニャ度回転させた場合の座標を取得する方法なんて

2011-06-27 01:07:30 | Weblog
using 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 三角関数サンプル
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void pictureBox1_Paint(object sender, PaintEventArgs e)
{
//下記は、三角関数を用いて自力で回転させている。

//傾ける角度
int angle = -90;

//基準となる線
int X = 50;
int startY = 70;
int endY = 120;

using (Pen whitePen = new Pen(Color.White))
{





//もとの線
e.Graphics.DrawLine(whitePen, new Point(X,startY), new Point(X,endY));

//Point angledPoint = GetPoint(angle, X, startY, endY);
//Point angledEndPoint = GetPoint(angle, X, endY + (endY - startY), endY);
//e.Graphics.DrawLine(whitePen, angledPoint, angledEndPoint);


e.Graphics.DrawLine(whitePen, GetKaitenGyoretu((double)X, (double)startY, (double)X, (double)endY, (double)angle), new Point(X, endY));

}

int testX = 40;
int testY = 75;
using (Pen orangePen = new Pen(Color.Orange))
{

//もとの線
e.Graphics.DrawLine(orangePen, new Point(testX, testY), new Point(X, endY));


e.Graphics.DrawLine(orangePen, GetKaitenGyoretu((double)testX, (double)testY, (double)X, (double)endY, (double)angle), new Point(X, endY));

}


}



//任意点を基準とした回転行列を使う
//X・・・xcos? - ysin? Y・・・xsin? + ycos?

private Point GetKaitenGyoretu(double x, double y, double standardX, double standardY, double angle)
{
//下記をしてみては?
// 1.回転の中心を原点に平行移動
//2.回転
//3.回転の中心を元の位置に平行移動


double radianAngle = GetRadian(360 - angle);
double trueX = x - standardX;
double trueY = y - standardY;

double retX =trueX * Math.Cos(radianAngle) - trueY * Math.Sin(radianAngle);
double retY = trueX * Math.Sin(radianAngle) + trueY * Math.Cos(radianAngle);

return new Point((int)(retX + standardX), (int)(retY + standardY));



}







//ある点を基準点からホニャ度移動した場合の座標を求める
private Point GetHonya(double x, double y, double standardX, double standardY, double angle)
{

double length = geoLength(x, y, standardX, standardY);
double cosTest = Math.Cos(GetRadian(90 - angle));
double sinTest = Math.Sin(GetRadian(90 - angle));
double cosValue = length * cosTest;
double sinValue = length * sinTest;
return new Point((int)(standardX - cosValue), (int)(standardY - sinValue));






}


 /// <summary>
  /// 2点か間の距離計算
  /// </summary>
  /// <param name="x1">X座標その1</param>
  /// <param name="y1">y座標その1</param>
  /// <param name="x2">X座標その2</param>
  /// <param name="y2">y座標その2</param>
  /// <returns>2点間の距離</returns>
  public double geoLength( double x1 , double y1 ,
                     double x2 ,double y2)
  {
   double ret = Math.Sqrt(Math.Pow(x2 - x1 , 2) +
                     Math.Pow(y2 - y1 , 2) ) ;
   return ret;
  }



private Point GetPoint(int angle, int X, int startY, int endY)
{
int length= endY - startY;
double tes = Math.Cos(GetRadian(90-angle));
double sinTest = Math.Sin(GetRadian(90 - angle));
double tett = length * tes;
double tettttt = length * sinTest;
return new Point(X - (int)tett, endY - (int)tettttt);








}

private double GetRadian(double target)
{
return target / (180 / Math.PI);
}


private Point testm (double x1, double y1, double standardX, double standardY, double angle)
{
double x, y;


angle = 360 -angle;//反時計回りにする

double radianAngle = Math.PI * angle / 180.0;//Radianに変換
x = x1 * Math.Cos(radianAngle) - y1 * Math.Sin(radianAngle);
y = x1 * Math.Sin(radianAngle) + y1 * Math.Cos(radianAngle);


return new Point((int)( x), (int)( y));
}

private void button1_Click(object sender, EventArgs e)
{
//double x1, y1, x, y, a, angle;
//x1 = Double.Parse(textBox1.Text);
//y1 = Double.Parse(textBox2.Text);
//a = Double.Parse(textBox3.Text);
//angle = Math.PI * a / 180.0;
//x = x1 * Math.Cos(angle) - y1 * Math.Sin(angle);
//y = x1 * Math.Sin(angle) + y1 * Math.Cos(angle);
//textBox4.Text = x.ToString("F3");
//textBox5.Text = y.ToString("F3");
}
}
}

C# でエクセル操作方法

2011-06-05 09:23:19 | Weblog
公式
http://support.microsoft.com/kb/302902/ja

☆覚書
http://www.din.or.jp/~graywing/csharp_excel.html#SHEET_INSERT

Excel読み込み
http://d.hatena.ne.jp/kurukuru-papa/20100704/1278243371

型の動的な使用
http://msdn.microsoft.com/ja-jp/library/k3a58006%28v=vs.80%29.aspx

C#からExcelファイルを操作する方法
http://tkizawa.cocolog-nifty.com/blog/2008/02/cexcel_90ee.html

C#によるExcelの操作例
http://www4.pf-x.net/~rafysta/memo/wiki.cgi?page=C%23%A4%CB%A4%E8%A4%EBExcel%A4%CE%C1%E0%BA%EE%CE%E3

質問・C# Excel 操作 EXEが残り続ける
http://social.msdn.microsoft.com/forums/ja-jp/csharpgeneralja/thread/0F210F52-3667-4E66-9DD6-4480EEDE48DE




オブジェクト開放
http://jeanne.wankuma.com/tips/csharp/programming/releasecom.html

Excel COM をエレガントに扱う試み
http://igeta.cocolog-nifty.com/blog/2007/07/excel_com.html

データテーブルをEXCELに出力する。
http://architect360.apricot-jp.com/500tips/excel.html

http://kchon.blog111.fc2.com/blog-entry-28.html