1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
| namespace WindowsFormsApplication2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
//Step.Text = "0.2";
}
string line;
int counter;
double zmin; double zmax; double range; int nbstep;
List<double> steps = new List<double>();
private void button1_Click(object sender, EventArgs e)
{
open();
}
public DataTable open()
{
openFileDialog1.ShowDialog();
string filename = openFileDialog1.FileName;
//StreamReader file = new StreamReader(filename);
int i = 0;
//création du tableau
StreamReader file1 = new StreamReader(filename);
DataTable table = new DataTable();
table.Columns.Add("X", typeof(double));//double [] X = new double [counter];
table.Columns.Add("Y", typeof(double));//double [] Y = new double [counter];
table.Columns.Add("Z", typeof(double)); //double[] Z = new double[counter];
table.Columns.Add("Dist", typeof(double));//double [] Dist = new double [counter];
table.Columns.Add("Angle", typeof(double)); double[] Angle = new double[counter];
float centrex = 1000; float centrey = 1000;
List<double> angle = new List<double>();
while ((line = file1.ReadLine()) != null)
{
char[] delimiters = new char[] { ',' };
string[] words = line.Split(delimiters, StringSplitOptions.RemoveEmptyEntries);
DataRow row = table.NewRow();
row["X"]= Convert.ToDouble(words[0], new CultureInfo("en-US"));
row["Y"] = Convert.ToDouble(words[1], new CultureInfo("en-US"));
row["Z"] = Convert.ToDouble(words[2], new CultureInfo("en-US"));
row["Dist"] = Math.Sqrt( Math.Pow(Convert.ToDouble(words[0], new CultureInfo("en-US")) - centrex, 2) + Math.Pow(Convert.ToDouble(words[1], new CultureInfo("en-US")) - centrey, 2));
row["Angle"] =180* Math.Atan2(Convert.ToDouble(words[1], new CultureInfo("en-US")) - centrey, Convert.ToDouble(words[0], new CultureInfo("en-US")) - centrex)/Math.PI;
table.Rows.Add(row);
i++;
}
file1.Close();
//table.DefaultView.Sort = "[Angle] ASC";
DataView dv = table.DefaultView;
dv.Sort = "Angle";
table = dv.ToTable();
//min = table.Select("Z = Max(Z)");
Zmin.Text = Convert.ToString(table.Compute("Min(Z)", string.Empty))+ " m";//Convert.ToString( table.Select("Z = Max(Z)"));
Zmax.Text = Convert.ToString(table.Compute("Max(Z)", string.Empty)) + " m";
Zmin.Visible = true; Zmax.Visible = true;
zmax = Convert.ToDouble(table.Compute("Max(Z)", string.Empty));
zmin = Convert.ToDouble(table.Compute("Min(Z)", string.Empty));
return table;
}
private void button2_Click(object sender, EventArgs e)
{
if (listBox1.Items.Count > 1)
{
listBox1.DataSource = null;
listBox1.Items.Clear();
steps.Clear();
}
int i = 0;
range = zmax - zmin;
nbstep = Convert.ToInt32(range / Convert.ToDouble(Step.Text, new CultureInfo("en-US")));
for (i = 0; i < nbstep; i++)
{
steps.Add(Math.Round(zmin + Convert.ToDouble(Step.Text, new CultureInfo("en-US")) * i, 2));
}
listBox1.DataSource = steps;
}
}
} |
Partager