using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Media.Media3D;
using System.Windows.Forms;
using System.Drawing;
using System.Runtime.Caching;
using Microsoft.Kinect;
namespace Spiel
{
public partial class MainWindow : Window
{
private List<Vector> auswählen = new List<Vector>();
private List<double> Timer = new List<double>();
private List<double> Rotationswinkel = new List<double>();
private List<double> Flexionswinkel = new List<double>();
private double[] a;
private double[] b;
private double[] c;
// Vector3D ShoulderRight = new Vector3D(body.Joints[JointType.ShoulderRight].Position.X, body.Joints[JointType.ShoulderRight].Position.Y, body.Joints[JointType.ShoulderRight].Position.Z);
Vector3D ShoulderRight = new Vector3D(2, 1, 0);
// Vector3D ElbowRight = new Vector3D(body.Joints[JointType.ElbowRight].Position.X, body.Joints[JointType.ElbowRight].Position.Y, body.Joints[JointType.ElbowRight].Position.Z);
Vector3D ElbowRight = new Vector3D(0, 0, 0);
// Vector3D WristRight = new Vector3D(body.Joints[JointType.WristRight].Position.X, body.Joints[JointType.WristRight].Position.Y, body.Joints[JointType.WristRight].Position.Z);
Vector3D WristRight = new Vector3D(-3, 6, -8);
// Vector3D ThumbRight = new Vector3D(body.Joints[JointType.ThumbRight].Position.X, body.Joints[JointType.ThumbRight].Position.Y, body.Joints[JointType.ThumbRight].Position.Z);
Vector3D ThumbRight = new Vector3D(4, 4, 4);
public MainWindow()
{
InitializeComponent();
Vector M = new Vector (Width / 2, Height/2);
auswählen = new List<Vector>();
auswählen.Add(new Vector(10, 90));
auswählen.Add(new Vector(20, 90));
auswählen.Add(new Vector(30, 90));
}
System.Windows.Threading.DispatcherTimer timerSend = new System.Windows.Threading.DispatcherTimer();
System.IO.StreamWriter sw;
public void button_Click(object sender, RoutedEventArgs e)
{
//prüfen, ob noch ein Listenelement vorhanden ist
bool isEmpty = !auswählen.Any();
if (isEmpty)
{
System.Windows.MessageBox.Show("Vielen Dank an Ihrer Teilnahme. Drücken Sie bitte den Save Button");
}
else
{
Random rnd = new Random();
int index = rnd.Next(0, auswählen.Count - 1);
Vector3D Oberarm = ShoulderRight - ElbowRight; Vector3D Unterarm = ElbowRight - WristRight; Vector3D Daumen = WristRight - ThumbRight;
//Berechnung des Flexionswinkels
Double dotProduct; dotProduct = Vector3D.DotProduct(Oberarm, Unterarm); Double length1; length1 = Oberarm.Length; Double length2; length2 = Unterarm.Length;
calc = Math.Round((Math.Acos(dotProduct / (length1 * length2)) * 180 / Math.PI), 0);
// Berechnung des Rotationswinkel
calc2 = Convert.ToInt32(textBox3.Text);
textBox2.Text = (auswählen[index].ToString());
textBox4.Text = calc.ToString();
Vector versuch = new Vector(calc, calc2);
// zufälliger Vektor(Flexion,Rotation) des Exakten Bereiches +- 0 Grad
double x = auswählen[index].X; double y = auswählen[index].Y; Canvas.SetLeft(Exakter_Bereich, x); Canvas.SetTop(Exakter_Bereich, -y);
// zufälliger Vektor(Flexion,Rotation) des Toleranzbereiches +- 2 Grad
double xx = auswählen[index].X; double yy = auswählen[index].Y; Canvas.SetLeft(Toleranzbereich, xx); Canvas.SetTop(Toleranzbereich, -yy);
Canvas.SetLeft(Ansteuern, calc2); Canvas.SetTop(Ansteuern, -calc);
double X2 = calc2; double Y2 = calc;
//float r = (float) Math.Pow((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1), 0.5);
double a = MainGrid.ActualWidth / 2; double b = MainGrid.ActualHeight / 2;
// Berechnung der Längen
double R_auswählen = Math.Round(Math.Pow(Math.Pow((auswählen[index].X) - a, 2) + Math.Pow((auswählen[index].Y - b), 2), 0.5), 2); label1.Content = R_auswählen;
double R_ansteuern = Math.Round(Math.Pow(Math.Pow((calc2 - a), 2) + Math.Pow((calc - b), 2), 0.5), 2); label4.Content = R_ansteuern;
if (zahl >= 3)
{
zahl = 0;
}
// Rotationswinkel, Flexionswinkel exakt
if (((auswählen[index].X == calc2)) && (auswählen[index].Y == calc))
{
textBox5.Text = "Grüner Bereich";
timerSend.Interval = TimeSpan.FromSeconds(0.01);
timerSend.Tick += tick;
timerSend.Start();
auswählen.RemoveAt(index);
textBox1.Text = String.Join(Environment.NewLine, auswählen);
if (ctr >=2.98)
{
ctr = 0;
}
}
else
{// Rotationswinkel größer gleich 0 Grad und kleiner gleich 2 Grad Flexionswinkel größer gleich 88 Grad und kleiner gleich 92 Grad
if (((auswählen[index].X <= calc2 + 2) && (auswählen[index].X >= calc2 - 2) && auswählen[index].Y <= calc + 2) && (auswählen[index].Y >= calc - 2))
{
textBox5.Text = "Gelber Bereich";
timerSend.Interval = TimeSpan.FromSeconds(0.1);
timerSend.Tick += tick;
timerSend.Start();
}
else
{
textBox5.Text = "nochmal";
}
}
}
}
public double calc2 { get; private set; }
public double calc { get; private set; }
float zahl = 0.0f;
float ctr = -0.1f;
void tick(object sender, EventArgs e)
{
zahl += 0.1f;
ctr += 0.1f;
double Beispieltimer = Math.Round(zahl, 2);
Timer.Add(Beispieltimer);
Flexionswinkel.Add(calc);
Rotationswinkel.Add(calc2);
if (zahl >= 3)
{
timerSend.Stop();
}
}
private void button1_Click(object sender, RoutedEventArgs e)
{
sw = new System.IO.StreamWriter(@"C:...\Test.txt");
sw.Flush();
sw.WriteLine("{0,5:N2} {1,5:N2} {2,5:N2}", Timer.ToString(), Rotationswinkel.ToString(),Flexionswinkel.ToString());
sw.Close();
Close();
}
}
}