Git Product home page Git Product logo

Comments (2)

SkybuckFlying avatar SkybuckFlying commented on August 25, 2024

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.

SkybuckFlying avatar SkybuckFlying commented on August 25, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.