CrossPoints function not working for vertical lines

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
NojaPower
Newbie
Newbie
Posts: 6
Joined: Fri Feb 22, 2008 12:00 am

CrossPoints function not working for vertical lines

Post by NojaPower » Thu Sep 24, 2009 5:03 am

Hi,
The CrossPoints function is not calculating intersections correctly for vertical line segments. That is, in one of the lines being tested for intersection the x values are the same.

I have resolved the issue to Drawing.Graphics3D.CrossingLines() function. The x and y parameters are being set to NaN because of the calculation method.

I resolved the issue using the following replacement function:

Code: Select all

private bool CrossingLines(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4, out double x, out double y)
{
	double ua_t = (x4 - x3) * (y1 - y3) - (y4 - y3) * (x1 - x3);
	double ub_t = (x2 - x1) * (y1 - y3) - (y2 - y1) * (x1 - x3);
	double u_b  = (y4 - y3) * (x2 - x1) - (x4 - x3) * (y2 - y1);

	x = double.NaN;
	y = double.NaN;

	if ( u_b != 0 ) 
	{
		double ua = ua_t / u_b;
		double ub = ub_t / u_b;

		if ( 0 <= ua && ua <= 1 && 0 <= ub && ub <= 1 )
		{
			x = x1 + ua * (x2 - x1);
			y = y1 + ua * (y2 - y1);

			if (x == 0 && y == 0)
				return false;
			
			return true;
		}
	}
	
	return false;
}

I have tested it with a variety of gradients/line lengths and it is ok. You may want to test it further before usage.

Cheers,
NojaPower

Yeray
Site Admin
Site Admin
Posts: 9614
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: CrossPoints function not working for vertical lines

Post by Yeray » Thu Sep 24, 2009 11:13 am

Hi NojaPower,

Could you please send us a simple example project or a snipped of code to see in what exact situation do you see this bad calculation?

Thanks in advance.
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

NojaPower
Newbie
Newbie
Posts: 6
Joined: Fri Feb 22, 2008 12:00 am

Re: CrossPoints function not working for vertical lines

Post by NojaPower » Thu Sep 24, 2009 9:59 pm

Hi Yeray,
Pass in coordinates in which one of the lines is vertical (i.e. the x coordinates are the same value), and the other intersects the vertical line at some point. CrossingLInes() will return true, but the value of x and y are NaN.

Cheers,
NojaPower

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Re: CrossPoints function not working for vertical lines

Post by Narcís » Tue Sep 29, 2009 8:21 am

Hi NojaPower,

Thanks for your feedback. I have been able to get this working with code below, with which existing implementation doesn't work. However, it doesn't work adding 4 additional points to line1 (commented code). It doesn't work with HorizLine series either. Anyway I've added your request to the list to be investigated further and considered for inclusion in next releases.

Code: Select all

	  public Form1()
	  {
	    InitializeComponent();
			InitializeChart();
		}

		private void InitializeChart()
		{
			tChart1.Aspect.View3D = false;

			Steema.TeeChart.Styles.Line line1 = new Steema.TeeChart.Styles.Line(tChart1.Chart);
			Steema.TeeChart.Styles.Line line2 = new Steema.TeeChart.Styles.Line(tChart1.Chart);
			
			line1.XValues.Order = Steema.TeeChart.Styles.ValueListOrder.None;
			line1.FillSampleValues();
			
			double tmp = line1.MinXValue() + ((line1.MaxXValue() - line1.MinXValue()) / 2);
			line2.Add(tmp, line1.MinYValue());
			line2.Add(tmp, line1.MaxYValue());
			//line2.FillSampleValues();

			//line1.Add(0, 0);
			//line1.Add(25, line1.MaxYValue());
			//line1.Add(0, line1.MaxYValue());
			//line1.Add(25, 0);

			Steema.TeeChart.Functions.CrossPoints crossPoints1 = new Steema.TeeChart.Functions.CrossPoints(tChart1.Chart);
			Steema.TeeChart.Styles.Line line3 = new Steema.TeeChart.Styles.Line(tChart1.Chart);
			line3.DataSource = new object[] { line1, line2 };
			line3.Function = crossPoints1;
			line3.Pointer.Visible = true;
		}
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Post Reply