Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use LLA (Latitude, Longitude, Altitude) coordinates instead of ECEF (Earth-Centered Earth-Fixed) coordinates #2

Open
Ahmedgis opened this issue Nov 10, 2014 · 5 comments

Comments

@Ahmedgis
Copy link

My Problem is i want to use this library to check the intersection between a Line and a Polygon both of them are drawing using a 3D coordinates WGS84 (Latitude, Longitude, Altitude), as i found that this library only accept ECEF (Earth-Centered Earth-Fixed) coordinates (X,Y,Z).

The line will consists of (2 Points) and the Polygon will consists of (4 Points or more) in Lat,Lon,Alt

So i want to know how can i use the real WGS84 (Lat,Lon,Alt) coordinates instead of using (X,Y,Z).

I hope that i clarify my problem to you.

Thanks in advance

@michaelosthege
Copy link
Owner

Okay, in this case I suggest to first convert the coordinates to cartesian space (XYZ).

Take a look at this thread: http://stackoverflow.com/questions/1185408/converting-from-longitude-latitude-to-cartesian-coordinates

There are multiple solutions how to do the conversion.

Afterwards, you can use TCD.Mathematics to calculate the intersection. But be careful with the scale - there might be rounding problems if you do this in kilometers etc…

Von: Ahmedgis
Gesendet: ‎Montag‎, ‎10‎. ‎November‎ ‎2014 ‎17‎:‎41
An: michaelosthege/TCD.Mathematics

My Problem is i want to use this library to check the intersection between a Line and a Polygon both of them are drawing using a 3D coordinates WGS84 (Latitude, Longitude, Altitude), as i found that this library only accept ECEF (Earth-Centered Earth-Fixed) coordinates (X,Y,Z).

The line will consists of (2 Points) and the Polygon will consists of (4 Points or more) in Lat,Lon,Alt

So i want to know how can i use the real WGS84 (Lat,Lon,Alt) coordinates instead of using (X,Y,Z).

I hope that i clarify my problem to you.

Thanks in advance


Reply to this email directly or view it on GitHub.

@Ahmedgis
Copy link
Author

Thanks for your reply, i successfully converted the coordinates to cartesian space (XYZ), but i faced another problem when i tried to use the intersection method i can not find the suitable input parameters that can solve my problem (see the Image ).

polygon line intersection

In the attached image i want to draw a 3D surface (3D poylgon) with known 4 points defined by (P1,P2,P3,P4) in WGS84 Geographic coordinates (Lat,Lon,Alt) and 2 lines (L1, L2) defined by 2 points for each line both are in (Lat,Lon,Alt) format both lines are based\started from the ground the ground surface (Black surface) and perpendicular to it like a tower or antenna.

So i want to use the intersection method to check if Line 1 or Line 2 intersect with the surface and the point of intersection and the intersection length, as the sample in the image (Line 1) penetrate the surface but (Line 2) didn't.

thanks

@michaelosthege
Copy link
Owner

Okay, there are multiple things you have to calculate to solve this problem:

Four points do not always lie in the same plane - therefore you should make two triangles first. Both triangles (3 Point3D objects) can be used to define two new Plane3D(p1,p2,p3) and Plane3D(p1,p3,p4).

The Line3D(p5,p6) can then be intersected with the plane, resulting in Point3D s1. Then you need to check weather s1 is within the triangle (you can do that eg. via angles between the triangle corners and the point) and between the points of the line (p5, p6 - the vectors (s1-p5) and (s1-p6) need to point in the same direction).

Finally you do this with both triangles and lines and apply some boolean logic on the results to answer your question.

Have fun

@Ahmedgis
Copy link
Author

Thanks for you reply

I tried the method that you said, assuming the following:

1 - The surface is flat , all points Altitude =500m.
2 - Dividing the surface to 2 triangles (T1(p1,p2,p3), T2(p1,p3,p4)).
3 - Line (1) starting from 0m altitude to 600m, perpendicular on the surface and penetrating it.
4 - Line (2) starting from 0m altitude to 400m, perpendicular on the surface and below it.
5 - Both Lines are inside the surface in 2D and in the same (Lat,Lon) position but deference altitudes.
6 - Creating a test project - check Link.

An Image to clarify what i did
polygon line intersection2

The test project i created

https://app.box.com/s/2dwtfhm22lfl2xjb7xl7

Results:

The library works fine when checking the intersection if the line's start, end points are higher than the surface (i.e: If the line (P1 altitude >= 501m) and (Line P2 altitude > 501m)), but when the line starts from the ground (0m) or from any other lower altitude than the surface the result always TRUE for Intersection even its End point is lower than the surfce - it should be no intersection -.

Kindly find attached a test project that i created.

Thanks for your help

@michaelosthege
Copy link
Owner

You are on the right path! But you have to understand: The Line3D (just like Plane3D) is an infinite object. You may define it by two points, but the object itself is a point and a vector. Therefore it does NOT have ends.

A Line3D will have one intersection with a Plane3D unless it's parallel (ParallelityException) or lies in the plane (IdentityException if I remember correctly). Make sure to catch these exceptions. (The same goes for other methods in the library that mathematically can have none or infinite solutions.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants