Page 1 of 1

CrossPoints function not working for vertical lines

Posted: Thu Sep 24, 2009 5:03 am
by 13048389
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

Re: CrossPoints function not working for vertical lines

Posted: Thu Sep 24, 2009 11:13 am
by yeray
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.

Re: CrossPoints function not working for vertical lines

Posted: Thu Sep 24, 2009 9:59 pm
by 13048389
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

Re: CrossPoints function not working for vertical lines

Posted: Tue Sep 29, 2009 8:21 am
by narcis
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;
		}