Algorithm is fine, but make sure you unified units
Closed this issue · 0 comments
LingboTang commented
Again, your algorithm is robust now, but it's not "unit-generic". Because you are using meters by default, if someone is using km or miles or ft your function might not find the correct solution. It's not a bug, but it's a "good to have" feature you might want to add.
For example:
I give:
var point1 = {latitude: 53.3048837, longitude: -113.5229284};
var point2 = {latitude: 53.3048617, longitude: -113.5229180};
var point3 = {latitude: 53.3048847, longitude: -113.5229264};
And I transfer it to Cartesian coordinates and geo datum wgs84:
{"x":-1524434.6754203958,"y":-3502126.5305430577,"z":5090891.040060376,"r":1.4270310588489077}
{"x":-1524434.8232832425,"y":-3502128.607318933,"z":5090889.57698756,"r":1.2248652566563933}
{"x":-1524434.5175572485,"y":-3502126.5019345237,"z":5090891.106563669,"r":1.464081291918516}
And I pass them in your function, it will not work properly because you will return two identical value in 7 digits. You don't need to add a really small threshold. It really depends on the input value.