Skip to content

Instantly share code, notes, and snippets.

@vitek999
Created March 12, 2016 16:46
Show Gist options
  • Save vitek999/ebe010641fb2cd1e514e to your computer and use it in GitHub Desktop.
Save vitek999/ebe010641fb2cd1e514e to your computer and use it in GitHub Desktop.
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;
namespace Test_Alpha_govnokod_
{
public partial class Graph : Form
{
Form2 logger = new Form2();
double alpha, Vx0, Vy0, Vx, Vy, V0, l, H , t1, t2, Y2, time;
private void button2_Click(object sender, EventArgs e)
{
System.Drawing.Graphics formGraphics = this.CreateGraphics();
System.Drawing.Pen myPen;
System.Drawing.Pen myPen1;
myPen = new System.Drawing.Pen(System.Drawing.Color.Red);
myPen1 = new System.Drawing.Pen(System.Drawing.Color.Gray);
formGraphics.Clear(Color.WhiteSmoke);
Graph_Load(sender, e);
}
private void label9_Click(object sender, EventArgs e)
{
}
double g = 9.81;
int x1, x2, x3, x4, x5, y1, y2, y3, y4, y5 ,
X0 = 40 ,Y0 = 400;
public void trackBar1_Scroll(object sender, EventArgs e)
{
alpha = trackBar1.Value;
label1.Text = ("Grad: " + alpha.ToString());
}
int GraphX, GraphY, X, Y;
private void Graph_Load(object sender, EventArgs e)
{
System.Drawing.Graphics formGraphics = this.CreateGraphics();
System.Drawing.Pen myPen;
System.Drawing.Pen myPen1;
myPen = new System.Drawing.Pen(System.Drawing.Color.Red);
myPen1 = new System.Drawing.Pen(System.Drawing.Color.Gray);
System.Drawing.Pen mainPen;
mainPen = new System.Drawing.Pen(System.Drawing.Color.Black);
formGraphics.DrawLine(myPen1, 500, 400, 500, 40);
formGraphics.DrawLine(mainPen, 40, 400, 500, 400);
formGraphics.DrawLine(mainPen, 40, 400, 40, 40);
GraphX = 40;
GraphY = 40;
while (GraphX < 500)
{
GraphX += 10;
formGraphics.DrawLine(myPen1, GraphX, 400, GraphX, 40);
}
while (GraphY < 400)
{
formGraphics.DrawLine(myPen1, 40, GraphY, 500, GraphY);
GraphY += 10;
}
}
public Graph()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
//logger.Show();
if (textBox1.Text == "")
{
MessageBox.Show("Error!");
}
else if (Int32.Parse(textBox1.Text) > 21)
{
MessageBox.Show("max speed - 20 m/s");
}
else
{
//Graph
System.Drawing.Graphics formGraphics = this.CreateGraphics();
System.Drawing.Pen myPen;
System.Drawing.Pen myPen1;
myPen = new System.Drawing.Pen(System.Drawing.Color.Red);
myPen1 = new System.Drawing.Pen(System.Drawing.Color.Gray);
System.Drawing.Pen mainPen;
mainPen = new System.Drawing.Pen(System.Drawing.Color.Black);
//Math
//Vy0 and Vx0
V0 = Int32.Parse(textBox1.Text);
Vy0 = (V0 * (Math.Sin((alpha / 180D) * Math.PI)));
label3.Text = Vy0.ToString();
Vx0 = (V0 * (Math.Cos((alpha / 180D) * Math.PI)));
label4.Text = Vx0.ToString();
//L - max
l = ((V0 * V0 * (Math.Sin(((2 * alpha) / 180D) * Math.PI))) / g);
label5.Text = "L - " + l.ToString() + "m";
double l1 = l * 10;
//logger.ButLog("l = " + l1.ToString());
//H-max
H = ((V0 * V0 * (Math.Pow((Math.Sin((alpha / 180D) * Math.PI)), 2))) / 20 * g);
label6.Text = ("H - " + H.ToString() + "m");
//logger.ButLog("H = " + H.ToString());
x5 = ((40 + Convert.ToInt32(l1)));
//logger.ButLog("x5 = " + x5.ToString());
x3 = (40 + Convert.ToInt32(l1/2));
//logger.ButLog("x3 = " + x3.ToString());
y3 = ((400 - (Convert.ToInt32(H))));
//logger.ButLog("y3 = " + y3.ToString());
Point[] apt = new Point[3];
apt[0] = new Point(X0, 400);
apt[1] = new Point(x3, y3);
apt[2] = new Point(x5, 400);
formGraphics.DrawCurve(myPen, apt, 0, 2, 0.5f);
myPen.Dispose();
formGraphics.Dispose();
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment