The method usually loop over the points defined for the shape from first to last.
The added 2 tell it to not check the first line segment between the first and second point, but rather start at the second line segment.
The second argument is useful if you want to find the possible second, third, ... intersection point as the code just return the first one found as it is.
I haven't begun to write documentation for it, as I daily add and adjust more functionality to code that this is based on, at work, as I have to handle more and more all the time. This is my attempt to clean up the code and structure it better.
"intersects" return .true or .false if they intersect
"intersect" return the line segments that intersect as a number dot number
"intersectionPoint" now return the point of intersection
Note! The PolyShape class is unaware of the curvature of the earth, so it is inaccurate for larger distances. PolyShape calculate the intersection point for a flat surface.
Polygon.cls can contain and handle for example holes in the shape
WGS84.cls handle functionality for earth curvature suitable with google kml files and gps. Need help to find code here to calculate intersection point for a curved surface such as the earth.
Feel free to test each class and method, document what they can and can't do.
I've tested a package that "document" classes automatically, and it seem to do a nice job, but one need to add useful insights, examples and explain what each class should be used for.
I would also be pleased if for example method "offset" could be completed to return shapes with
a) correct offset for ends when used with both side offset, not only inside or outside.
b) clean up of line segments that overlap due to large offset distance.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Jan, Thank you. I have been using OORexx for nearly 40 years and I am getting better all the time but when I look at your code I am still an amateur. Keep up the great work.
Cheers,
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I'm new to ooRexx as it wasn't ported to OS/2 and Object Rexx wasn't the default interpreter on OS/2 so one could not rely on that is was enabled, while classic rexx was.
May not do things as efficient as one could, but that is because how and what the descriptions/documentation say how to write code.
Polygon and related code/classes mostly use techniques found in school book examples though there usually written in other languages.
I think that "rexx" would be useful in education as at least pseudo code, but often usable code to create understanding.
BTW I changed the self~decimals = 3 to 6 in PolyShape.Cls so the tostring gives the full 6 decimal places. Having 3 decimal places is not too useful for navigation . I think you should make it 6 as most users would not know how to change it.
Will checkout your other files later.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Jan-Erik,
I seem to still have a problem finding the intersectionpoint of two lines when the angle between them is small. Here is what I found:
BG_LN=.PolyShape~new('-77.619237,20.631839 -77.619237,20.698505')say'BG_LN='BG_LNLG_LN=.PolyShape~new('-77.617041,20.698442 -77.621432, 20.631902')say'LG_LN='LG_LNsay'intersect='LG_LN~intersect(BG_LN)--say'intersects='LG_LN~intersects(BG_LN)IP1=LG_LN~intersectionPoint(BG_LN)if .Nil<>IP1thensay'intersectionPoint='IP1~yIP1~xelsesay'intersectionPoint is .Nil'
the result is:
BG_LN=a Line
LG_LN=a Line
intersect=1.1
intersects=1
intersectionPoint is .Nil
if I decrease the angle of the BG_LN it works
LN =.PolyShape~new('-77.619237,20.631839 -77.622473,20.698414')
BG_LN=a Line
LG_LN=a Line
intersect=1.1
intersects=1
intersectionPoint=20.6510311 -77.6201699
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
OK I found the problem: at the end of the intersectionpoint method you do compares and some fail because they are are not formatted to the same number of decimal places. Fixed it by:
I changed all formats in my previous post to: ~format(18,self~decimals)~strip
to make it compatible with all decimal values.
But to make that test above work I had to change the self~decimals = 6 for the Polyshape class and use .Polyshape for both lines because if I use WGS84 in my test for both the lines it always returns .Nil
like this:
BG_LN=.WGS84~new('-77.619237,20.631839 -77.619237,20.698505')say'BG_LN='BG_LNLG_LN=.PolyShape~new('-77.617041,20.698442 -77.621432, 20.631902')say'LG_LN='LG_LNsay'intersect='LG_LN~intersect(BG_LN)--say'intersects='LG_LN~intersects(BG_LN)IP1=LG_LN~intersectionPoint(BG_LN)if .Nil<>IP1thensay'intersectionPoint='IP1~yIP1~xelsesay'intersectionPoint is .Nil'
returns:
BG_LN=a Line
LG_LN=a Line
intersect=0
intersects=0
intersectionPoint is .Nil
So I can't use WGS84 or I am I missing the point?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Added use of self~format( ... ) to calculation for px and py instead. I should have thought about it as the method crop that I develop for work also require it.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
/* PolyShape can't handle WGS84 shapes as WGS84 is based on PolyShape and not the other way around, with 'an Array' in between */
BG_LN=.wgs84~new('-77.619237,20.631839 -77.619237,20.698505')say'BG_LN='BG_LN~toString(,,,'')--OBS!!ComparewithLG_LN
LG_LN=.wgs84~new
LG_LN~decimals=6--Setthisaswellifyoureplacewgs84withpolyshapeonthelineabove
LG_LN~prepare('-77.617041,20.698442 -77.621432, 20.631902')say'LG_LN='LG_LN~toString(,,.True)--OBS!!UsetoStringtogetformattedoutput
say'intersect='LG_LN~intersect(BG_LN)--SettoBG_LN~shapes[1]ifBG_LN=.wGS84&LG_LN=.PolyShape
say'intersects='LG_LN~intersects(BG_LN)--SettoBG_LN~shapes[1]ifBG_LN=.wGS84&LG_LN=.PolyShape
IP1=LG_LN~intersectionPoint(BG_LN)--SettoBG_LN~shapes[1]ifBG_LN=.wGS84&LG_LN=.PolyShape
if.Nil<>IP1thensay'intersectionPoint='ip1~toString(.false)--SeetoStringin.Point,.PolyShapeetc.elsesay'intersectionPoint is .Nil'::requires'WGS84.cls'::requires'PolyShape.cls'
Google use "Lat,Lng" for an individual point, that is in reversed order, while not for polylines and polygons.
longitude = x
latitude = y
elevation = z or e
<...> indicate optional parameter
The point class can use/handle/interpret these formats:
pnt = .point~new( x, y<, z> ) -- each set individually
pnt2 = .point~new( '(x,%20y<,%20z>)' ) -- interpret string as point found in web pages
pnt3 = .point~new( '(x,y<,z>)' ) -- interpret string as point
pnt4 = .point~new( 'y,x<,e>' ) -- interpret point from google string seen in google maps etc.
So use paranthesis around, such as '(x,y)', to interpret in longitude,latitude order.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Yes, it works great. Thank you.
Question on the : intersectionPoint( LS2, 2 ) what does the ",2" do? If I delete it it gives same result.
Also, is there some documentation to explain what all the methods do?
Last edit: Paul Higgins 2022-02-05
The method usually loop over the points defined for the shape from first to last.
The added 2 tell it to not check the first line segment between the first and second point, but rather start at the second line segment.
The second argument is useful if you want to find the possible second, third, ... intersection point as the code just return the first one found as it is.
I haven't begun to write documentation for it, as I daily add and adjust more functionality to code that this is based on, at work, as I have to handle more and more all the time. This is my attempt to clean up the code and structure it better.
"intersects" return .true or .false if they intersect
"intersect" return the line segments that intersect as a number dot number
"intersectionPoint" now return the point of intersection
Note! The PolyShape class is unaware of the curvature of the earth, so it is inaccurate for larger distances. PolyShape calculate the intersection point for a flat surface.
Polygon.cls can contain and handle for example holes in the shape
WGS84.cls handle functionality for earth curvature suitable with google kml files and gps. Need help to find code here to calculate intersection point for a curved surface such as the earth.
Feel free to test each class and method, document what they can and can't do.
I've tested a package that "document" classes automatically, and it seem to do a nice job, but one need to add useful insights, examples and explain what each class should be used for.
I would also be pleased if for example method "offset" could be completed to return shapes with
a) correct offset for ends when used with both side offset, not only inside or outside.
b) clean up of line segments that overlap due to large offset distance.
Jan, Thank you. I have been using OORexx for nearly 40 years and I am getting better all the time but when I look at your code I am still an amateur. Keep up the great work.
Cheers,
Thanks,
I'm new to ooRexx as it wasn't ported to OS/2 and Object Rexx wasn't the default interpreter on OS/2 so one could not rely on that is was enabled, while classic rexx was.
May not do things as efficient as one could, but that is because how and what the descriptions/documentation say how to write code.
Polygon and related code/classes mostly use techniques found in school book examples though there usually written in other languages.
I think that "rexx" would be useful in education as at least pseudo code, but often usable code to create understanding.
Jan, if you have time look at this.
I define two polygons: see the attachment, the first polygon is in blue the second in yellow. They have two intersection points.
The output is:
intersect=1.1
IP0 intersectionPoint=8.59255535 117.522379
IP0 intersectionPoint=8.59255535 117.522379
How do I see the 2nd intersection point ?
Thanks
Hadn't removed a thing in delta...
well, here's some more to play with
2RectPoly
to test PolyShape.clsodc WGS84.cls
to list classesJan,
Yes that fixed it thanks.
BTW I changed the self~decimals = 3 to 6 in PolyShape.Cls so the tostring gives the full 6 decimal places. Having 3 decimal places is not too useful for navigation . I think you should make it 6 as most users would not know how to change it.
Will checkout your other files later.
It's deliberate, as I want you to use:
a) Polygon (and WGS84 that already use more decimals).
b) LS0~decimals = 6
Last edit: Jan-Erik Lärka 2022-02-07
Jan-Erik,
I seem to still have a problem finding the intersectionpoint of two lines when the angle between them is small. Here is what I found:
the result is:
BG_LN=a Line
LG_LN=a Line
intersect=1.1
intersects=1
intersectionPoint is .Nil
if I decrease the angle of the BG_LN it works
LN =.PolyShape~new('-77.619237,20.631839 -77.622473,20.698414')
BG_LN=a Line
LG_LN=a Line
intersect=1.1
intersects=1
intersectionPoint=20.6510311 -77.6201699
OK I found the problem: at the end of the intersectionpoint method you do compares and some fail because they are are not formatted to the same number of decimal places. Fixed it by:
I changed all formats in my previous post to:
~format(18,self~decimals)~strip
to make it compatible with all decimal values.
But to make that test above work I had to change the self~decimals = 6 for the Polyshape class and use .Polyshape for both lines because if I use WGS84 in my test for both the lines it always returns .Nil
like this:
returns:
BG_LN=a Line
LG_LN=a Line
intersect=0
intersects=0
intersectionPoint is .Nil
So I can't use WGS84 or I am I missing the point?
Added use of self~format( ... ) to calculation for px and py instead. I should have thought about it as the method crop that I develop for work also require it.
Thanks for the update. But I still can not use WGS84.
Jan-Erik,
Something is really confusing to me. Why do you reverse the x and y for a point. For example:
the result is:
PT=8.490863 117.501452
Google use "Lat,Lng" for an individual point, that is in reversed order, while not for polylines and polygons.
longitude = x
latitude = y
elevation = z or e
<...> indicate optional parameter
The point class can use/handle/interpret these formats:
pnt = .point~new( x, y<, z> ) -- each set individually
pnt2 = .point~new( '(x,%20y<,%20z>)' ) -- interpret string as point found in web pages
pnt3 = .point~new( '(x,y<,z>)' ) -- interpret string as point
pnt4 = .point~new( 'y,x<,e>' ) -- interpret point from google string seen in google maps etc.
So use paranthesis around, such as '(x,y)', to interpret in longitude,latitude order.