sslnjz / geodesy Goto Github PK
View Code? Open in Web Editor NEWLibraries of geodesy functions implemented in c++
License: MIT License
Libraries of geodesy functions implemented in c++
License: MIT License
const int sign =
(n == std::nullopt) ||
( cross(*n).dot(*n) >= 0 ? 1 : -1);
????
TESTING SEEMS TO INDICATE TO RETURN 1 IF NO PARAMETER... WHAT DOES IT DO IF THERE IS A PARAMETER ?! MAYBE I SHOULDNT EVEN CARE BUT STIL.. BYE..
TWO EXAMPLES:
*/
double angleTo(const vector3d& v, const std::optional& n = std::nullopt) const
{
// q.v. stackoverflow.com/questions/14066933#answer-16544330, but n·p₁×p₂ is numerically
// ill-conditioned, so just calculate sign to apply to |p₁×p₂|
// if n·p₁×p₂ is -ve, negate |p₁×p₂|
const int sign = n == std::nullopt || cross(v).dot(*n) >= 0 ? 1 : -1;
const double sintheta = cross(v).length() * sign;
const double costheta = dot(v);
return std::atan2(sintheta, costheta);
}
int PieceOfShit( const std::optional<vector3d>& n = std::nullopt) const
{
// q.v. stackoverflow.com/questions/14066933#answer-16544330, but n·p₁×p₂ is numerically
// ill-conditioned, so just calculate sign to apply to |p₁×p₂|
// if n·p₁×p₂ is -ve, negate |p₁×p₂|
const int sign =
(n == std::nullopt) ||
( cross(*n).dot(*n) >= 0 ? 1 : -1);
return sign;
}
FINALLY FOUND THIS FUCKING ALGORITHM FUCKING FILE OF YOURS
IN SRC\UTILS
OH MY GOD, I THOUGHT IT WAS SOMETHING ADVANCED OR SOMETHING...
XsssssssssssssssssssssssssssX
See picture in second comment for problem.
See here for example pairs fail, near end of video:
https://www.youtube.com/live/-EsixpO9mBk?feature=share
// engineer who provided it to you for assistance.
// Define some earth constants
const MAJA = (6378137.0); // semi major axis of ref ellipsoid
const FLAT = (1.0/298.2572235630); // flattening coef of ref ellipsoid.
// These are derived values from the above WGS-84 values
const ESQR = (FLAT * (2.0-FLAT)); // 1st eccentricity squared
const OMES = (1.0 - ESQR); // 1 minus eccentricity squared
const EFOR = (ESQR * ESQR); // Sqr of the 1st eccentricity squared
const ASQR = (MAJA * MAJA); // semi major axis squared := nlmaja**
procedure ConvertECEFToLTP
(
const ParaEcef : TEcef;
var ParaLtp : TLtp
);
var
a0,a1,a2,a3,a4,b0,b1,b2,b3 : double;
b,c0,opqk,qk,qkc,qks,f,fprm : double;
k : integer;
ytemp, xtemp : double;
begin
// Convert from ParaEcef (XYZ) to LTP (ParaLtp.Lat/ParaLtp.Lon/ParaLtp.Alt)
//-------------------------------------------
// b := (0*0 + 1*1) / semi_major_axis_squared
// c := (z*z) / semi_major_axis_squared
//-------------------------------------------
b :=
(
(ParaEcef.x * ParaEcef.x) +
(ParaEcef.y * ParaEcef.y)
) / ASQR;
c0 :=
(ParaEcef.z * ParaEcef.z) / ASQR;
//-------------------------------------------
// a0 := c * one_minus_eccentricity_sqr
// a1 := 2 * a0
// a2 := a0 + b - first_eccentricity_to_fourth
// a3 := -2.0 * first_eccentricity_to_fourth
// a4 := - first_eccentricity_to_fourth
//-------------------------------------------
a0 := OMES * c0;
a1 := 2.0 * a0;
a2 := a0 + b - EFOR;
a3 := -2.0 * EFOR;
a4 := - EFOR;
//-------------------------------------------
// b0 := 4 * a0, b1 := 3 * a1
// b2 := 2 * a2, b3 := a3
//-------------------------------------------
b0 := 4.0 * a0;
b1 := 3.0 * a1;
b2 := 2.0 * a2;
b3 := a3;
//-------------------------------------------
// Compute First Eccentricity Squared
//-------------------------------------------
qk := ESQR;
// for (k := 1; k <:= 3; k++)
for k := 1 to 3 do
begin
qks := qk * qk;
qkc := qk * qks;
f :=
(a0 * qks * qks) +
(a1 * qkc) +
(a2 * qks) +
(a3 * qk) + a4;
fprm :=
(b0 * qkc) +
(b1 * qks) +
(b2 * qk) + b3;
qk := qk - (f / fprm);
end;
//-------------------------------------------
// Compute latitude, longitude, altitude
//-------------------------------------------
opqk := 1.0 + qk;
if
(
(ParaEcef.x = 0.0) and
(ParaEcef.y = 0.0)
) then
// on the earth's axis
begin
// We are sitting EXACTLY on the earth's axis
// Probably at the center or on or near one of the poles
ParaLtp.Lon := 0.0; // as good as any other value
if (ParaEcef.z >= 0.0) then
begin
ParaLtp.Lat := PI / 2; // ParaLtp.Alt above north pole
end else
begin
ParaLtp.Lat := -PI / 2; // ParaLtp.Alt above south pole
end;
end else
begin
ytemp := opqk * ParaEcef.z;
xtemp := sqrt
(
( ParaEcef.x * ParaEcef.x ) +
( ParaEcef.y * ParaEcef.y )
);
ParaLtp.Lat := arctan2( ytemp, xtemp );
ParaLtp.Lon := arctan2( ParaEcef.y, ParaEcef.x );
end;
ParaLtp.Alt :=
(
1.0 - OMES / ESQR * qk
) * MAJA *
sqrt
(
(
b / (opqk * opqk)
) + c0
);
end; // ConvertECEFToLTP()
// written by Skybuck Flying ! ;) :) =D
function ClosestPointDistanceToClosestPointOnSegment
(
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
vPoint,
vSegmentPoint1,
vSegmentPoint2,
vClosestPointOnSegment : TLatLonNvectorSpherical;
begin
vSegmentPoint1.FromXYZ2( ParaStartX, ParaStartY, ParaStartZ, ParaRadius );
vSegmentPoint2.FromXYZ2( ParaEndX, ParaEndY, ParaEndZ, ParaRadius );
vPoint.FromXYZ2( ParaPointX, ParaPointY, ParaPointZ, ParaRadius );
vClosestPointOnSegment := nearestPointOnSegment
(
vPoint,
vSegmentPoint1,
vSegmentPoint2,
ParaRadius
);
result := distanceTo
(
vPoint, vClosestPointOnSegment, ParaRadius
);
end;
function ClosestPointDistanceToClosestPointOnSegmentV2
(
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
vPoint,
vSegmentPoint1,
vSegmentPoint2,
vClosestPointOnSegment : TLatLonNvectorSpherical;
vEcef : Tecef;
vLtp : Tltp;
begin
// convert start x,y,z to lat lng
vEcef.X := ParaStartX;
vEcef.Y := ParaStartY;
vEcef.Z := ParaStartZ;
ConvertECEFToLTP
(
vEcef,
vLtp
);
vSegmentPoint1.mLat := vLtp.Lat;
vSegmentPoint1.mLon := vLtp.Lon;
// convert end x,y,z to lat lang
vEcef.X := ParaEndX;
vEcef.Y := ParaEndY;
vEcef.Z := ParaEndZ;
ConvertECEFToLTP
(
vEcef,
vLtp
);
vSegmentPoint2.mLat := vLtp.Lat;
vSegmentPoint2.mLon := vLtp.Lon;
// ParaRadius ??
// convert point x,y,z to lat lng
vEcef.X := ParaPointX;
vEcef.Y := ParaPointY;
vEcef.Z := ParaPointZ;
ConvertECEFToLTP
(
vEcef,
vLtp
);
vPoint.mLat := vLtp.Lat;
vPoint.mLon := vLtp.Lon;
vClosestPointOnSegment := nearestPointOnSegment
(
vPoint,
vSegmentPoint1,
vSegmentPoint2,
ParaRadius
);
result := distanceTo
(
vPoint, vClosestPointOnSegment, ParaRadius
);
end;
Any idea what could be wrong ? If you need more code let me know...
1>E:\SourceCode\test optional garbage\ConsoleApplication1\vector3d.h(39,10): fatal error C1083: Cannot open include file: 'algorithm.h': No such file or directory
IF REMOVED IT GUESS WORSE:
Build started...
1>------ Build started: Project: ConsoleApplication1, Configuration: Debug Win32 ------
1>Build started 16-2-2023 5:28:55.
1>Target InitializeBuildStatus:
1> Touching "Debug\ConsoleA.5af436db.tlog\unsuccessfulbuild".
1>Target VcpkgTripletSelection:
1> Using triplet "x86-windows" from "E:\SourceCode\vcpkg\scripts\buildsystems\msbuild......\installed\x86-windows"
1>Target ClCompile:
1> ConsoleApplication1.cpp
1> The contents of are available only with C++17 or later.
1> E:\SourceCode\test optional garbage\ConsoleApplication1\vector3d.h(201,48): error C2039: 'optional': is not a member of 'std'
1> C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\include\sstream(20): message : see declaration of 'std'
1> E:\SourceCode\test optional garbage\ConsoleApplication1\vector3d.h(201,56): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1> E:\SourceCode\test optional garbage\ConsoleApplication1\vector3d.h(201,56): error C2143: syntax error: missing ',' before '<'
1> E:\SourceCode\test optional garbage\ConsoleApplication1\vector3d.h(127,25): error C3861: 'essentiallyEqual': identifier not found
1> E:\SourceCode\test optional garbage\ConsoleApplication1\vector3d.h(206,21): error C2065: 'n': undeclared identifier
1> E:\SourceCode\test optional garbage\ConsoleApplication1\vector3d.h(206,31): error C2039: 'nullopt': is not a member of 'std'
1> C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\include\sstream(20): message : see declaration of 'std'
1> E:\SourceCode\test optional garbage\ConsoleApplication1\vector3d.h(206,1): error C2065: 'nullopt': undeclared identifier
1> E:\SourceCode\test optional garbage\ConsoleApplication1\vector3d.h(206,56): error C2065: 'n': undeclared identifier
1> E:\SourceCode\test optional garbage\ConsoleApplication1\vector3d.h(206,14): error C2737: 'sign': const object must be initialized
1> E:\SourceCode\test optional garbage\ConsoleApplication1\vector3d.h(221,25): error C3861: 'toRadians': identifier not found
1> E:\SourceCode\test optional garbage\ConsoleApplication1\vector3d.h(319,12): error C3861: 'essentiallyEqual': identifier not found
1> E:\SourceCode\test optional garbage\ConsoleApplication1\vector3d.h(320,6): error C3861: 'essentiallyEqual': identifier not found
1> E:\SourceCode\test optional garbage\ConsoleApplication1\vector3d.h(321,6): error C3861: 'essentiallyEqual': identifier not found
1>Done building target "ClCompile" in project "ConsoleApplication1.vcxproj" -- FAILED.
1>
1>Done building project "ConsoleApplication1.vcxproj" -- FAILED.
1>
1>Build FAILED.
1>
1>E:\SourceCode\test optional garbage\ConsoleApplication1\vector3d.h(201,48): error C2039: 'optional': is not a member of 'std'
1>E:\SourceCode\test optional garbage\ConsoleApplication1\vector3d.h(201,56): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>E:\SourceCode\test optional garbage\ConsoleApplication1\vector3d.h(201,56): error C2143: syntax error: missing ',' before '<'
1>E:\SourceCode\test optional garbage\ConsoleApplication1\vector3d.h(127,25): error C3861: 'essentiallyEqual': identifier not found
1>E:\SourceCode\test optional garbage\ConsoleApplication1\vector3d.h(206,21): error C2065: 'n': undeclared identifier
1>E:\SourceCode\test optional garbage\ConsoleApplication1\vector3d.h(206,31): error C2039: 'nullopt': is not a member of 'std'
1>E:\SourceCode\test optional garbage\ConsoleApplication1\vector3d.h(206,1): error C2065: 'nullopt': undeclared identifier
1>E:\SourceCode\test optional garbage\ConsoleApplication1\vector3d.h(206,56): error C2065: 'n': undeclared identifier
1>E:\SourceCode\test optional garbage\ConsoleApplication1\vector3d.h(206,14): error C2737: 'sign': const object must be initialized
1>E:\SourceCode\test optional garbage\ConsoleApplication1\vector3d.h(221,25): error C3861: 'toRadians': identifier not found
1>E:\SourceCode\test optional garbage\ConsoleApplication1\vector3d.h(319,12): error C3861: 'essentiallyEqual': identifier not found
1>E:\SourceCode\test optional garbage\ConsoleApplication1\vector3d.h(320,6): error C3861: 'essentiallyEqual': identifier not found
1>E:\SourceCode\test optional garbage\ConsoleApplication1\vector3d.h(321,6): error C3861: 'essentiallyEqual': identifier not found
1> 0 Warning(s)
1> 13 Error(s)
1>
1>Time Elapsed 00:00:01.72
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
THIS OPTIONAL THING IS FUCKING ANNOYING
double angleTo(const vector3d& v, const std::optional& n = std::nullopt) const
{
// q.v. stackoverflow.com/questions/14066933#answer-16544330, but n·p₁×p₂ is numerically
// ill-conditioned, so just calculate sign to apply to |p₁×p₂|
// if n·p₁×p₂ is -ve, negate |p₁×p₂|
const int sign = n == std::nullopt || cross(v).dot(*n) >= 0 ? 1 : -1;
// const int sign = n == std::nullopt || cross(v).dot(*n) >= 0 ? true : false;
const double sintheta = cross(v).length() * sign;
const double costheta = dot(v);
return std::atan2(sintheta, costheta);
}
DONT MAKE CODE UNNECESSARY COMPLEX !!!!
Preferably for Windows system and Visual Studio...
I tried it, current it gives errors:
cmake -DBUILD_TESTING=OFF -DBUILD_SHARED_LIBS=ON
"
Make Error at test/CMakeLists.txt:39 (find_package):
Could not find a package configuration file provided by "geodesy" with any
of the following names:
geodesyConfig.cmake
geodesy-config.cmake
Add the installation prefix of "geodesy" to CMAKE_PREFIX_PATH or set
"geodesy_DIR" to a directory containing one of the above files. If
"geodesy" provides a separate development package or SDK, be sure it has
been installed.
"
I don't know CMake well enough to do it... it has like billions of pages of documentation...
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.