
I need to get the intersection points of 2 series. iam using zedgraph


Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Tuhin PaulRank #7 · 71.9K reputationPosted Feb 18, 2024, 9:25 AM EST
To find the intersection points of two series in ZedGraph, you can iterate through the points of each series and compare them to find the intersections. ZedGraph does not provide built-in functionality for finding intersections.
using System; using System.Collections.Generic; using ZedGraph; class Program { static void Main(string[] args) { // Create two sample series PointPairList series1 = new PointPairList(new double[] { 1, 2, 3, 4 }, new double[] { 1, 2, 3, 4 }); PointPairList series2 = new PointPairList(new double[] { 2, 3, 4, 5 }, new double[] { 1, 2, 3, 4 }); // Find intersection points List intersectionPoints = FindIntersectionPoints(series1, series2); // Output intersection points Console.WriteLine("Intersection Points:"); foreach (PointPair point in intersectionPoints) { Console.WriteLine($"X: {point.X}, Y: {point.Y}"); } } static List FindIntersectionPoints(PointPairList series1, PointPairList series2) { List intersectionPoints = new List(); // Iterate through each point of series1 for (int i = 0; i < series1.Count - 1; i++) { PointPair point1 = series1[i]; PointPair point2 = series1[i + 1]; // Iterate through each point of series2 for (int j = 0; j < series2.Count - 1; j++) { PointPair point3 = series2[j]; PointPair point4 = series2[j + 1]; // Check for intersection between line segments PointPair intersection = FindIntersection(point1, point2, point3, point4); if (intersection != null) { intersectionPoints.Add(intersection); } } } return intersectionPoints; } static PointPair FindIntersection(PointPair p1, PointPair p2, PointPair p3, PointPair p4) { // Implementation of intersection logic goes here // For simplicity, let's assume no intersection in this example return null; } }Tuhin PaulRank #7 · 71.9K reputationPosted Feb 18, 2024, 9:25 AM EST
An alternative approach to finding the intersection points of two series in ZedGraph is to utilize mathematical methods for line intersection detection. One common method is to use vector algebra to find the intersection point of two lines. Here's a general outline of how you can implement this approach:
using System; using System.Collections.Generic; using ZedGraph; class Program { static void Main(string[] args) { // Create two sample series PointPairList series1 = new PointPairList(new double[] { 1, 2, 3, 4 }, new double[] { 1, 2, 3, 4 }); PointPairList series2 = new PointPairList(new double[] { 2, 3, 4, 5 }, new double[] { 1, 2, 3, 4 }); // Find intersection points List intersectionPoints = FindIntersectionPoints(series1, series2); // Output intersection points Console.WriteLine("Intersection Points:"); foreach (PointPair point in intersectionPoints) { Console.WriteLine($"X: {point.X}, Y: {point.Y}"); } } static List FindIntersectionPoints(PointPairList series1, PointPairList series2) { List intersectionPoints = new List(); // Iterate through each pair of adjacent points in the two series for (int i = 0; i = Math.Min(p1.X, p2.X) && x = Math.Min(p1.Y, p2.Y) && y = Math.Min(p3.X, p4.X) && x = Math.Min(p3.Y, p4.Y) && y <= Math.Max(p3.Y, p4.Y))) { return new PointPair(x, y); } return null; // No intersection } }