Calculate line and plane relationships, etc
This article introduces some commonly used mathematical calculation methods for line and plane relationships, including:
- Determine whether a point is inside a surfaceAMap.GeometryUtil.isPointInRing
- Determine whether a point is on a line segmentAMap.GeometryUtil.isPointOnSegment
- Calculate the intersection area of two latitude and longitude surfacesAMap.GeometryUtil.ringRingClip
1、Determine if a point is within a polygon
When you need to determine if a specified point is within a closed region, you can use the static method AMap.GeometryUtil.isPointInRing, which returns a boolean value.
var p0 = [100.485843, 13.754169];
var p1 = [100.483397, 13.75542];
var p2 = [100.492237, 13.755503];
var p3 = [100.485543, 13.746833];
//Determine if p0 is within the closed region bounded by p1-p2-p3
var inRing = AMap.GeometryUtil.isPointInRing(p0, [p1, p2, p3]);2、Determine if a point is on a line segment
When you need to calculate whether a specified point is on a line segment, you can use the static method AMap.GeometryUtil.isPointOnSegment, which returns a Boolean value.
var p0 = [100.480865, 13.751293];
var p1 = [100.476402, 13.75121];
var p2 = [100.485628, 13.751376];
//Determine whether p0 is on the line segment formed by p1-p2, with the last parameter being an error margin of 100 meters
var inLine = AMap.GeometryUtil.isPointOnSegment(p0, p1, p2, 100);3、Calculate the intersection area of two surfaces
When you need to calculate the intersection area of two surfaces, you can use the static method AMap.GeometryUtil.ringRingClip to return the path of the intersection area.
var p0 = [100.48271, 13.754586];
var p1 = [100.482624, 13.749334];
var p2 = [100.490092, 13.747541];
var p3 = [100.492709, 13.756128];
//Calculate the intersection area of surface p0-p1-p2 and surface p3-p1-p2. Return the intersection path, and if there is no intersection, the path will be empty.
var range = AMap.GeometryUtil.ringRingClip([p0, p1, p2], [p3, p1, p2]);