I am trying to do some geometry calculation (e.g distance from point to line) on 2D planar planes.
Currently investigating turfjs
to calculate distance from point to line.
Code
distance.js:
// hello
var turf = require('@turf/turf')
init();
// init,
function init() {
distance();
}
function distance() {
// line
let line = turf.lineString([
[0, 0],
[3, 4]
]);
console.log(line);
// point
let point = turf.point([3, 0]);
console.log(point);
// calculate distance from point to line, using planar,
let dis = turf.pointToLineDistance(point, line, {
units: 'degrees',
method: 'planar'
});
console.log("distance: %f", dis);
}
Output
distance: 2.398995395932417
If I change point to [30, 0]
and line to [0, 0], [30, 40]
, then the output is:
distance: 25.741472914575986
The program is using degrees
as unit, and planar
as method.
The expected results are 2.4
and 24
, but it's not.
Question
- So, does that means those points are on a curved surface, instead of a flat plane?
- Is it possible to define points & lines & polygons in flat plane, instead of the curved surface?
- If not, then it there another similar tool to perform this task?