Comments (2)
I managed to convert the X,Y,Z coordinates to lat, long with these functions, both work... but use different methods...
My distance to visualize the line was simply to great giving the impression that maybe the current crossTrackDistanceTo function wasn't working or something was wrong, but it turns alright, though it doesn't respect the line segment concept... I'll might make new pull request for that.
//**
// * converts a XYZ THREE.Vector3 to longitude latitude. beware, the vector3 will be normalized!
// * @param vector3
// * @returns an array containing the longitude [0] & the lattitude [1] of the Vector3
// */
procedure TLatLon.FromXYZ( ParaX, ParaY, ParaZ : double );
var
vVector : TVector3D;
lng, lat : double;
p : TVector3D;
begin
vVector.mX := ParaX;
vVector.mY := ParaY;
vVector.mZ := ParaZ;
vVector.Normalize();
//longitude = angle of the vector around the Y axis
//-( ) : negate to flip the longitude (3d space specific )
//- PI / 2 to face the Z axis
lng := -( System.Math.arctan2( -vVector.mz, -vVector.mx ) ) - (System.PI / 2);
//to bind between -PI / PI
if( lng < -System.PI ) then lng := lng + (System.PI * 2);
//latitude : angle between the vector & the vector projected on the XZ plane on a unit sphere
//project on the XZ plane
p.mX := vVector.mX;
p.mY := 0;
p.mZ := vVector.mZ;
//project on the unit sphere
p.normalize();
//commpute the angle ( both vectors are normalized, no division by the sum of lengths )
lat := System.Math.arccos( p.Dot( vVector ) );
//invert if Y is negative to ensure teh latitude is comprised between -PI/2 & PI / 2
if ( vVector.mY < 0 ) then lat := lat * -1;
mLon := lng;
mLat := lat;
end;
procedure TLatLon.FromXYZ2( ParaX, ParaY, ParaZ : double; ParaSphereRadius : double );
begin
mLat := System.Math.ArcCos(ParaY / ParaSphereRadius); //theta
mLon := System.ArcTan(ParaX / ParaZ); //phi
end;
from geodesy.
I consider this more or less solved for now :) though maybe it can be done a little bit more efficient, without needing these conversions... I think so, but not entirely sure yet ! ;)
This was my initial version, maybe it's good enough for this functionality, but now I need other functionality :):
This code illustrates the removal of toNVector...
function ClosestDistancePointToGreatCircleV1
(
ParaPointX, ParaPointY, ParaPointZ : double;
ParaStartX, ParaStartY, ParaStartZ : double;
ParaEndX, ParaEndY, ParaEndZ : double;
ParaRadius : double = 6371e3 // (Mean) radius of earth (defaults to radius in metres).
) : double;
var
// also a possibility, thank god it works ! ;) :)
{
vPoint : unit_CrossTrackDistance_version_001.unit_TVector3D_version_001.TVector3D;
vStart : unit_CrossTrackDistance_version_001.unit_TVector3D_version_001.TVector3D;
vEnd : unit_CrossTrackDistance_version_001.unit_TVector3D_version_001.TVector3D;
vGreatCircle : unit_CrossTrackDistance_version_001.unit_TVector3D_version_001.TVector3D;
}
vPoint : TCrossDistanceVector3D;
vStart : TCrossDistanceVector3D;
vEnd : TCrossDistanceVector3D;
vGreatCircle : TCrossDistanceVector3D;
vAlpha : double;
begin
// vPoint := ParaPoint.toNvector(); // converts itself... to a 3d vector apperently...
vPoint.mX := ParaPointX;
vPoint.mY := ParaPointY;
vPoint.mZ := ParaPointZ;
// vGreatCircle := ParaPathStart.toNvector().cross(ParaPathEnd.toNvector()); // great circle defined by two points
vStart.mX := ParaStartX;
vStart.mY := ParaStartY;
vStart.mZ := ParaStartZ;
if vStart = vPoint then
begin
result := 0;
exit;
end;
vEnd.mX := ParaEndX;
vEnd.mY := ParaEndY;
vEnd.mZ := ParaEndZ;
vGreatCircle := vStart.cross( vEnd );
// vAlpha := vGreatCircle.AngleTo(vPoint) - (System.PI / 2); // angle between point & great-circle
vAlpha := vGreatCircle.AngleTo(vPoint) - (System.PI / 2); // angle between point & great-circle
result := vAlpha * ParaRadius;
end;
from geodesy.
Related Issues (20)
- Difference on geoscience australia example HOT 2
- How to use the library in Angular 2+ apps?
- True rhumbline distance
- Paypal Donate 404 at https://www.movable-type.co.uk/scripts/latlong-os-gridref.html HOT 2
- MGRS parsing issue HOT 1
- OSgrid Parsing Error HOT 2
- LatLonSpherical.intersection algorithm is different from edwilliams aviation formula. HOT 1
- Something wrong with CrossTrackDistanceTo ? It assumes a line instead of line segment ? HOT 3
- MinimumDistanceToLineSegment( Start, Stop, Point ); HOT 1
- ClosestPointDistanceToClosestPointOnSegment fails for some pairs on globe... see video and code.. any ideas ? HOT 1
- Point-Line Distance 3-Dimensional HOT 4
- how can i verify the destination point is right? HOT 1
- intersection between a circle and a great line segment
- World Geographic Reference System (GEOREF) conversion? HOT 1
- OS Grid Conversion in Jersey and Channel Islands HOT 1
- MGRS above 84N and below 80S HOT 1
- Reason for the do...while loop in toLatLon(), utm.js
- Intersection of two paths given start points, bearings and elevations
- Swift conversion - os_tm_eas_nor_to_lat_lon giving the deprecated OSGB36 lat/lon HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from geodesy.