How to create a line from nodes?
-
I have a File with NODES (x and y values). Is it possible to draw a line with this nodes , and can someone show me how to do it (read it from file and draw)? I am beginer :sigh: I would like to have it in my form, schould I create Pannel to draw on it or how :) This is how my file looks like 1 0.0000E+00 -0.4396E+01 2 0.1136E+01 -0.4506E+01 3 0.2217E+01 -0.4706E+01 4 0.3290E+01 -0.4953E+01 5 0.4355E+01 -0.5230E+01 6 0.5409E+01 -0.5519E+01 7 0.6447E+01 -0.5808E+01 8 0.7472E+01 -0.6075E+01 9 0.8488E+01 -0.6324E+01 10 0.9492E+01 -0.6548E+01 11 0.1049E+02 -0.6749E+01 12 0.1147E+02 -0.6926E+01 13 0.1245E+02 -0.7086E+01 14 0.1343E+02 -0.7230E+01 15 0.1440E+02 -0.7360E+01 16 0.1538E+02 -0.7476E+01 17 0.1636E+02 -0.7568E+01 18 0.1735E+02 -0.7649E+01 19 0.1833E+02 -0.7719E+01 20 0.1931E+02 -0.7782E+01 21 0.2030E+02 -0.7836E+01 22 0.2130E+02 -0.7869E+01 23 0.2230E+02 -0.7902E+01 24 0.2331E+02 -0.7936E+01 25 0.2431E+02 -0.7969E+01 26 0.2532E+02 -0.8003E+01 27 0.2632E+02 -0.8036E+01 28 0.2733E+02 -0.8070E+01 29 0.2833E+02 -0.8103E+01 30 0.2934E+02 -0.8137E+01 31 0.3034E+02 -0.8170E+01 32 0.3134E+02 -0.8204E+01 33 0.3235E+02 -0.8237E+01 34 0.3335E+02 -0.8271E+01 35 0.3435E+02 -0.8336E+01 36 0.3535E+02 -0.8404E+01 37 0.3635E+02 -0.8474E+01 38 0.3735E+02 -0.8547E+01 Thanx, .a.d.o.
-
I have a File with NODES (x and y values). Is it possible to draw a line with this nodes , and can someone show me how to do it (read it from file and draw)? I am beginer :sigh: I would like to have it in my form, schould I create Pannel to draw on it or how :) This is how my file looks like 1 0.0000E+00 -0.4396E+01 2 0.1136E+01 -0.4506E+01 3 0.2217E+01 -0.4706E+01 4 0.3290E+01 -0.4953E+01 5 0.4355E+01 -0.5230E+01 6 0.5409E+01 -0.5519E+01 7 0.6447E+01 -0.5808E+01 8 0.7472E+01 -0.6075E+01 9 0.8488E+01 -0.6324E+01 10 0.9492E+01 -0.6548E+01 11 0.1049E+02 -0.6749E+01 12 0.1147E+02 -0.6926E+01 13 0.1245E+02 -0.7086E+01 14 0.1343E+02 -0.7230E+01 15 0.1440E+02 -0.7360E+01 16 0.1538E+02 -0.7476E+01 17 0.1636E+02 -0.7568E+01 18 0.1735E+02 -0.7649E+01 19 0.1833E+02 -0.7719E+01 20 0.1931E+02 -0.7782E+01 21 0.2030E+02 -0.7836E+01 22 0.2130E+02 -0.7869E+01 23 0.2230E+02 -0.7902E+01 24 0.2331E+02 -0.7936E+01 25 0.2431E+02 -0.7969E+01 26 0.2532E+02 -0.8003E+01 27 0.2632E+02 -0.8036E+01 28 0.2733E+02 -0.8070E+01 29 0.2833E+02 -0.8103E+01 30 0.2934E+02 -0.8137E+01 31 0.3034E+02 -0.8170E+01 32 0.3134E+02 -0.8204E+01 33 0.3235E+02 -0.8237E+01 34 0.3335E+02 -0.8271E+01 35 0.3435E+02 -0.8336E+01 36 0.3535E+02 -0.8404E+01 37 0.3635E+02 -0.8474E+01 38 0.3735E+02 -0.8547E+01 Thanx, .a.d.o.
Well, this is a multi part question really. Where are you getting stuck on? Or are you needing assistance with some design as well?
"If a man empties his purse into his head, no man can take it away from him, for an investment in knowledge pays the best interest." -- Joseph E. O'Donnell Not getting the response you want from a question asked in an online forum: How to Ask Questions the Smart Way!
-
Well, this is a multi part question really. Where are you getting stuck on? Or are you needing assistance with some design as well?
"If a man empties his purse into his head, no man can take it away from him, for an investment in knowledge pays the best interest." -- Joseph E. O'Donnell Not getting the response you want from a question asked in an online forum: How to Ask Questions the Smart Way!
OK :) I am creating a little win application, in which I can select Input and Output Files for calculations I need. Calculation runs as a extern EXE File.. After ewerything is done, as result I get one text file where I can find data about NODEs (points) (x and y data). Now in my app, I need to create plot (drawing) in one pannel or something like that, a LINE which goes thrue my nodes.. I need to load this nodes file, (read it) and somehow create that plot.. And that is only for one moment, in next moment I have another Nodes position, and my LINE has changed.. So I taught, if I can do it for one time step (moment) I would change those pannels and so have something like an Animation..
-
OK :) I am creating a little win application, in which I can select Input and Output Files for calculations I need. Calculation runs as a extern EXE File.. After ewerything is done, as result I get one text file where I can find data about NODEs (points) (x and y data). Now in my app, I need to create plot (drawing) in one pannel or something like that, a LINE which goes thrue my nodes.. I need to load this nodes file, (read it) and somehow create that plot.. And that is only for one moment, in next moment I have another Nodes position, and my LINE has changed.. So I taught, if I can do it for one time step (moment) I would change those pannels and so have something like an Animation..
Okay, if I understand you correctly you want to draw a line between nodes 1 and 2, then a moment later between 3 and 4 and so on? Reading the file should be fairly easy:
ArrayList nodes = new ArrayList();
try
{
// Create an instance of StreamReader to read from a file.
// The using statement also closes the StreamReader.
using (StreamReader sr = new StreamReader("TestFile.txt"))
{
String line;
// Read and display lines from the file until the end of
// the file is reached.
while ((line = sr.ReadLine()) != null)
{
string[] values = line.Split(' '); // Splits the line at each space character// Convert the strings into numeric representations double x = Convert.ToDouble(values\[1\]); double y = Convert.ToDouble(values\[2\]); // Convert the x & y into a Point that can be used PointF node = new Point(x, y); nodes.Add(node); } }
}
catch (Exception e)
{
// Let the user know what went wrong.
}
// You now have an array list of nodes (PointF structures)DISCLAIMER: I typed this directly into the browser, there may be syntax errors.
"If a man empties his purse into his head, no man can take it away from him, for an investment in knowledge pays the best interest." -- Joseph E. O'Donnell Not getting the response you want from a question asked in an online forum: How to Ask Questions the Smart Way!
-
Okay, if I understand you correctly you want to draw a line between nodes 1 and 2, then a moment later between 3 and 4 and so on? Reading the file should be fairly easy:
ArrayList nodes = new ArrayList();
try
{
// Create an instance of StreamReader to read from a file.
// The using statement also closes the StreamReader.
using (StreamReader sr = new StreamReader("TestFile.txt"))
{
String line;
// Read and display lines from the file until the end of
// the file is reached.
while ((line = sr.ReadLine()) != null)
{
string[] values = line.Split(' '); // Splits the line at each space character// Convert the strings into numeric representations double x = Convert.ToDouble(values\[1\]); double y = Convert.ToDouble(values\[2\]); // Convert the x & y into a Point that can be used PointF node = new Point(x, y); nodes.Add(node); } }
}
catch (Exception e)
{
// Let the user know what went wrong.
}
// You now have an array list of nodes (PointF structures)DISCLAIMER: I typed this directly into the browser, there may be syntax errors.
"If a man empties his purse into his head, no man can take it away from him, for an investment in knowledge pays the best interest." -- Joseph E. O'Donnell Not getting the response you want from a question asked in an online forum: How to Ask Questions the Smart Way!
In one moment I need line thrue all points, in next moment I get another node set (in my file are meny node sets for diferent moments (time steps), and I should draw a whole new line.. As result I should have an Animation, where one line getting deformed (changes shape).. At first it is straight (First time step-moment): .................................................. at the End (last step) it should looks like: ...... . . ............... .................. (something like that :) I hope that U understand, I appologise about my poor English :)
-
In one moment I need line thrue all points, in next moment I get another node set (in my file are meny node sets for diferent moments (time steps), and I should draw a whole new line.. As result I should have an Animation, where one line getting deformed (changes shape).. At first it is straight (First time step-moment): .................................................. at the End (last step) it should looks like: ...... . . ............... .................. (something like that :) I hope that U understand, I appologise about my poor English :)
Okay, so you have one file. That file contains many node sets. A node set is a list of coordinates to draw a polyline through (lots of straight lines connecting each node). How do you determine from your file the start of a new node set? In the example you gave before, each line is numbered sequentially. I don't see anything to mark the start of a new set of nodes. Incidentally, did you understand my explanantion of reading the file?
"If a man empties his purse into his head, no man can take it away from him, for an investment in knowledge pays the best interest." -- Joseph E. O'Donnell Not getting the response you want from a question asked in an online forum: How to Ask Questions the Smart Way!
-
Okay, so you have one file. That file contains many node sets. A node set is a list of coordinates to draw a polyline through (lots of straight lines connecting each node). How do you determine from your file the start of a new node set? In the example you gave before, each line is numbered sequentially. I don't see anything to mark the start of a new set of nodes. Incidentally, did you understand my explanantion of reading the file?
"If a man empties his purse into his head, no man can take it away from him, for an investment in knowledge pays the best interest." -- Joseph E. O'Donnell Not getting the response you want from a question asked in an online forum: How to Ask Questions the Smart Way!
-
I have sent a sample file to You as attachment in mail message.. Its *.dat file, but You can open it with any text editor
Okay your file format, with all the spaces properly preserved is as follows (so anyone else can keep up with the thread
$ State Nr.: 150
1 0.0000E+00 -0.4396E+01
2 0.1136E+01 -0.4506E+01
3 0.2217E+01 -0.4706E+01The easiest thing to do is when reading the file, each line that starts with a $ denotes a new node, so you can use a line like:
if (line[0] == '$')
{
// Set up new node set here.
}So, before you start reading your file you might want to create an array to hold the node sets in, then each time you encounter a dollar symbol at the start of a line you can create a new array to hold each of the nodes in. The array of nodes gets added to the array of the nodesets. A node set is an array of nodes. Then when you have finshed reading the file you will have an array of node sets (in other words an array of arrays). Does this help?
"If a man empties his purse into his head, no man can take it away from him, for an investment in knowledge pays the best interest." -- Joseph E. O'Donnell Not getting the response you want from a question asked in an online forum: How to Ask Questions the Smart Way!
-
Okay your file format, with all the spaces properly preserved is as follows (so anyone else can keep up with the thread
$ State Nr.: 150
1 0.0000E+00 -0.4396E+01
2 0.1136E+01 -0.4506E+01
3 0.2217E+01 -0.4706E+01The easiest thing to do is when reading the file, each line that starts with a $ denotes a new node, so you can use a line like:
if (line[0] == '$')
{
// Set up new node set here.
}So, before you start reading your file you might want to create an array to hold the node sets in, then each time you encounter a dollar symbol at the start of a line you can create a new array to hold each of the nodes in. The array of nodes gets added to the array of the nodesets. A node set is an array of nodes. Then when you have finshed reading the file you will have an array of node sets (in other words an array of arrays). Does this help?
"If a man empties his purse into his head, no man can take it away from him, for an investment in knowledge pays the best interest." -- Joseph E. O'Donnell Not getting the response you want from a question asked in an online forum: How to Ask Questions the Smart Way!
-
Yes off course it helps, now I knew how to read it from file.. I will have to find a way to plot those lines somehow.. Thank You very much
For plotting your node list you could derive a class from
Panel
and then override theOnPaint
function. I'd save theArrayList
ofPoint
s as a property of your new class:protected ArrayList _graph = new ArrayList();
public ArrayList GraphPoints
{
get { return _graph; }
set { _graph = value; Invalidate(); }
}Then you can write something like this in the overridden function:
protected override void OnPaint(PaintEventArgs pe)
{
Point[] points = new Point[GraphPoints .Count];
GraphPoints .CopyTo(points);// DrawLines assumes (0,0) to be top left of the panel, so you might have
// to perform some coordinate transformation...
pe.Graphics.DrawLines(Pens.Red, points);
}Regards, mav