0

This is in reference to - Determine which side of a line a point lies

This an observation - I am trying to count points meeting my criteria using two of the above mentioned techniques i.e. the determinant using two reference points and third point to compare. Also alternatively I am using the slope method. Here, i already have a reference angle, one point fixed, and other varying points which need to be checked. so basically I am checking the angle which the lines are making with the horizontal.

I am getting different results, with the determinant, the result is approximately 3% more. Basically, more points are considered.

Any idea why this might be happening. Is this error in any way related to rounding off, in case of this being related to a rounding off error, which method is reliable? I am using tand() in matlab to compute the angles and then compare, and det() function to find the value of the determinant.

The code when comparing angles is as shown below

angle = E(l);
    while i+1 < len_y                       % Y co-ordinates
        while j+1 < len_x                   % X co-ordinates [The manner of saving the 2D matrix and the analysis are both in sync.]
            if z_1(i,j) <= z_1(i,j+1)       % check for the first peak
                j = j + 1;
            else z_1(i,j) > z_1(i,j+1);     % this is the first peak, where we set up the line
                while j+1 < len_x           % set up a line using the angle
                    z0 = z_1(i,j);          % this is the first point of the line
                    x0 = X(j);              
                        x1 = x0 + 10;           % problem solved.
                z1 = z0  - (tand(E(l)) * (x1 - x0)); % this is to setup the line to compare is a point is below or above it
                    j = j + 1;
                    trial_angle = atand((z0 - z_1(j))/(X(j) - x0));

                    while trial_angle > E(l) & j < len_x;         % check the first point of intersection of the line
                        j = j + 1;
                        trial_angle = atand((z0 - z_1(j))/(X(j) - x0));

                    end % end of points which are not in contact

I am using MATLAB 2012 and Win7 64 bit

Any help will be appreciated.

Thanks

thedorkknight

Community
  • 1
  • 1
thedorkknight
  • 183
  • 3
  • 12
  • Some of your code will be helpful – Adiel Jul 04 '13 at 07:19
  • I don't see `det` anywhere in your code (which of course isn't particularly helpful since it can't be run). I'd suggest that you find a specific point for which the two methods return a different result and investigate further. – horchler Jul 04 '13 at 16:49
  • A vectorized anonymous function for determining the side of a line that a point falls on via the determinant: `linesidedet=@(x1,y1,x2,y2,x3,y3)sign((x2-x1)*(y3(:)-y1)-(y2-y1)*(x3(:)-x1));`. Demo for a diagonal Y=X line and 10,000 normally distributed points: `side=linesidedet(0,0,1,1,randn(1e4,1),randn(1e4,1));nnz(side==1)`. – horchler Jul 04 '13 at 16:55

0 Answers0