slope of a line
-
I have a text file containing the following content:
0 12
1 15
2 6
3 4
4 3
5 6
6 12
7 8
8 8
9 9
10 13the first column specifies the x coordinate of a point and second column specifies the y coordinate.i need to read this file and find slope between all points. like first i find slope between (0,12) and (1,15) and then between (0,15) and (2,6) and so on.i am basically building a wpf application.can anyone help?
-
I have a text file containing the following content:
0 12
1 15
2 6
3 4
4 3
5 6
6 12
7 8
8 8
9 9
10 13the first column specifies the x coordinate of a point and second column specifies the y coordinate.i need to read this file and find slope between all points. like first i find slope between (0,12) and (1,15) and then between (0,15) and (2,6) and so on.i am basically building a wpf application.can anyone help?
The basic forumula for a slope is
(y2 - y1) / (x2 - x1
). Since you have all the co-ordinates, you can put them into an array and then run a loop over the array. You can also input them via a textbox on WPF.WP Apps - Color Search | Arctic | XKCD | Sound Meter | Speed Dial
-
The basic forumula for a slope is
(y2 - y1) / (x2 - x1
). Since you have all the co-ordinates, you can put them into an array and then run a loop over the array. You can also input them via a textbox on WPF.WP Apps - Color Search | Arctic | XKCD | Sound Meter | Speed Dial
i tried to put x and y coordinates in two different arrays but don't understand how to write a code that calculates the slope between points and displays them in a textbox. i have written the following code snippet:
var r = File.ReadAllLines(path)
.Select(line => line.Split(' '))
.Select(arr => new
{
Column0 = Int32.Parse(arr[0]),
Column1 = Int32.Parse(arr[1])
// etc
})
.ToArray();
int[] column0 = r.Select(x => x.Column0).ToArray();
int[] column1 = r.Select(x => x.Column1).ToArray(); -
i tried to put x and y coordinates in two different arrays but don't understand how to write a code that calculates the slope between points and displays them in a textbox. i have written the following code snippet:
var r = File.ReadAllLines(path)
.Select(line => line.Split(' '))
.Select(arr => new
{
Column0 = Int32.Parse(arr[0]),
Column1 = Int32.Parse(arr[1])
// etc
})
.ToArray();
int[] column0 = r.Select(x => x.Column0).ToArray();
int[] column1 = r.Select(x => x.Column1).ToArray();Try
for (int i=0; i<=column1.Count - 2;i++)
{
float slope = (column1[i+1] - column1[i])/(column0[i+1] - column0[i])
}WP Apps - Color Search | Arctic | XKCD | Sound Meter | Speed Dial
-
Try
for (int i=0; i<=column1.Count - 2;i++)
{
float slope = (column1[i+1] - column1[i])/(column0[i+1] - column0[i])
}WP Apps - Color Search | Arctic | XKCD | Sound Meter | Speed Dial
-
Try
for (int i=0; i<=column1.Count - 2;i++)
{
float slope = (column1[i+1] - column1[i])/(column0[i+1] - column0[i])
}WP Apps - Color Search | Arctic | XKCD | Sound Meter | Speed Dial
-
If (x2 - x1) is 0, the slope is infinity. Handle this case in code. Check and make sure (x2 - x1) is not 0 by a simple validation condition.
WP Apps - Color Search | Arctic | XKCD | Sound Meter | Speed Dial