Opened 15 years ago

Closed 15 years ago

#272 closed defect (fixed)

ST_LineCrossingDirection should be negatively symmetric

Reported by: robe Owned by: pramsey
Priority: medium Milestone: PostGIS 1.4.1
Component: postgis Version: 1.4.X
Keywords: Cc:

Description

I propose that to minimize on confusion

It should hold true that:

ST_LineCrossingDirection(a,b) = - ST_LineCrossingDirection(b,a)

--- below is a relevant excerpt from the previous crashing ticket -

Regina

But I think there is still a problem.

In our documentation -- We still have this example that doesn't behave right

SELECT ST_LineCrossingDirection(foo.line1, foo.line2) As l1_cross_l2 ,

    ST_LineCrossingDirection(foo.line2, foo.line1) As l2_cross_l1

FROM (SELECT

    ST_GeomFromText('LINESTRING(25 169,89 114,40 70,86 43)') As line1, ST_GeomFromText('LINESTRING(2.99 90.16,71 74,20 140,171 154)') As line2 ) As foo;

(gives me -2, 0)

http://www.postgis.org/documentation/manual-svn/ST_LineCrossingDirection.html 

Mark's Response

Yeah; I see exactly the same answers. Unfortunately though, I can't make much sense of the integer constants in the manual to work out what the function *should* actually be doing. Can anyone explain this in more detail? For example, do the LEFT/RIGHT parts refer to spatial position or the order of the input parameters?

ATB,

Mark.

Change History (2)

comment:1 by robe, 15 years ago

Hopefully I want embarass myself too much by my obvious lack of direction. ---

Now getting to the manual -- observe that in the manual there are 2 cases where our function is not negatively symmetric

http://www.postgis.org/documentation/manual-svn/ST_LineCrossingDirection.html

ELECT ST_LineCrossingDirection(foo.line1, foo.line2) As l1_cross_l2 ,
	  ST_LineCrossingDirection(foo.line2, foo.line1) As l2_cross_l1
FROM (
 SELECT
  ST_GeomFromText('LINESTRING(25 169,89 114,40 70,86 43)') As line1,
  ST_GeomFromText('LINESTRING (171 154, 20 140, 71 74, 2.99 90.16)') As line2
) As foo;

 l1_cross_l2 | l2_cross_l1
-------------+-------------
           2 |          -3

SELECT ST_LineCrossingDirection(foo.line1, foo.line2) As l1_cross_l2 ,
	  ST_LineCrossingDirection(foo.line2, foo.line1) As l2_cross_l1
FROM (SELECT
	ST_GeomFromText('LINESTRING(25 169,89 114,40 70,86 43)') As line1,
	ST_GeomFromText('LINESTRING(2.99 90.16,71 74,20 140,171 154)') As line2
	) As foo;

 l1_cross_l2 | l2_cross_l1
-------------+-------------
          -2 |          0

Now if you look at the diagram of these In case 1 -- the lines cross at 3 points, however from the perspective of the first line (green) -- the blue line crosses it on the left side first time, the second time right, and the 3rd time left. (you have to consider the directionality from the perspective of an observer walking from the start to end point of the first line -- and which side of him/her is the second line passing ).

The blue line (line 2) finally ends its journey on the left side relative to the green line. (2 : LINE MULTICROSS END RIGHT).

Now from the perspective of line 2 (the blue line) -- the green line crosses it in 3 places - at point one it is crossing to the right of it, at pt 2 it is crossing to the left of it and the third to the left of it. But they end up in different directions and their first crosses don't even seem in the same direction to me. Yet this is (-3) -- I guess I'm not quite sure what is meant by END SAME FIRST LEFT (because it would seem if one ends in same first left, the other should end same first right).

The second example is clearly wrong because -

how can one line cross another and the other doesn't cross it back except in the Twilight Zone :). This I think is clearly a number counting issue. Maybe we should just get rid of that 3,-3 option.

comment:2 by pramsey, 15 years ago

Resolution: fixed
Status: newclosed

I simplified the code a good deal, which should result in more consistent answers, and negatively symmetric answers. Trunk commit at r4786, 1.4 branch at r4787

Note: See TracTickets for help on using tickets.