Created
June 5, 2018 20:38
-
-
Save MarkusOstermayer/dfc76315ce8aeccf1e0d913595f25a64 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.ComponentModel; | |
using System.Data; | |
using System.Drawing; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
using System.Windows.Forms; | |
using newMV; | |
namespace VectorDrehungGUI | |
{ | |
public partial class Form1 : Form | |
{ | |
public Form1() | |
{ | |
InitializeComponent(); | |
} | |
private void onPanelPaint(object sender, PaintEventArgs e) | |
{ | |
Graphics gr = panel1.CreateGraphics(); | |
Vect3D v1 = Vect3D.ini; | |
v1.SetXYZ(80, 0, 0); | |
for (int i = 0; i < 360; i += 1) | |
{ | |
v1 = rotVectJan(v1, 0,0,i); | |
Point vectorpoint = v1.AsPoint(); | |
vectorpoint = Translate(vectorpoint, panel1); | |
gr.DrawLine(Pens.Green,panel1.Width / 2, panel1.Height / 2, vectorpoint.X, vectorpoint.Y); | |
} | |
} | |
public static Point Translate(Point aPoint,Panel pn) | |
{ | |
Point pt = new Point(); | |
pt.X = aPoint.X + pn.Width / 2; | |
pt.Y = aPoint.Y + pn.Height / 2; | |
return pt; | |
} | |
public static Vect3D rotVectJan(Vect3D oldVector, double x, double y, double z) | |
{ | |
//Drehung um die X-Achse | |
if (x != 0.0F) | |
{ | |
double newY = oldVector.Y * Math.Cos(DegreeToRadian(x)) - oldVector.Z * Math.Sin(DegreeToRadian(x)); | |
double newZ = oldVector.Y * Math.Sin(DegreeToRadian(x)) + oldVector.Z * Math.Cos(DegreeToRadian(x)); | |
oldVector.SetXYZ(oldVector.X, newY, newZ); | |
} | |
//Drehung um die Y-Achse | |
if (y != 0.0F) | |
{ | |
double newX = oldVector.Z * Math.Sin(DegreeToRadian(y)) + oldVector.X * Math.Cos(DegreeToRadian(y)); | |
double newZ = oldVector.Z * Math.Cos(DegreeToRadian(y)) - oldVector.X * Math.Sin(DegreeToRadian(y)); | |
oldVector.SetXYZ(newX, oldVector.Y, newZ); | |
} | |
//Drehung um die Z-Achse | |
if (z != 0.0F) | |
{ | |
double newX = oldVector.X * Math.Cos(DegreeToRadian(z)) - oldVector.Y * Math.Sin(DegreeToRadian(z)); | |
double newY = oldVector.X * Math.Sin(DegreeToRadian(z)) + oldVector.Y * Math.Cos(DegreeToRadian(z)); | |
oldVector.SetXYZ(newX, newY, oldVector.Z); | |
} | |
return oldVector; | |
} | |
private static double DegreeToRadian(double angle) | |
{ | |
return Math.PI * angle / 180.0; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment