A set of functions for working with geometries.
More...
#include <com/navigine/idl/objc/NCGeometryUtils.h>
Inherits NSObject.
A set of functions for working with geometries.
Definition at line 21 of file NCGeometryUtils.h.
◆ distanceBetweenGlobalPoints:to:
Get distance between GPS points.
- Parameters
-
- Returns
- distance in meters
Swift code snippet:
// Calculate distance between global points
let globalDistance = GeometryUtils.distanceBetweenGlobalPoints(from: globalPoint1, to: globalPoint2)
print("Distance between Moscow and St. Petersburg: \(String(format: "%.2f", globalDistance)) meters")
Objective C code snippet:
double globalDistance = [
NCGeometryUtils distanceBetweenGlobalPointsWithFrom:globalPoint1 to:globalPoint2];
NSLog(@"Distance between Moscow and St. Petersburg: %.2f meters", globalDistance);
◆ distanceBetweenPoints:to:
| + (float) distanceBetweenPoints: |
|
(nonnull NCPoint *) | from |
| to: |
|
(nonnull NCPoint *) | to |
Get distance between points.
- Parameters
-
| from | start point of calculation Point |
| to | end point of calculation Point |
- Returns
- distance in meters
Swift code snippet:
// Calculate distance between points
let distance = GeometryUtils.distanceBetweenPoints(from: point1, to: point2)
print("Distance between P1 and P2: \(String(format: "%.2f", distance)) meters")
Objective C code snippet:
double distance = [
NCGeometryUtils distanceBetweenPointsWithFrom:point1 to:point2];
NSLog(@"Distance between P1 and P2: %.2f meters", distance);
◆ divisionRatioBySegment:segment2:
| + (float) divisionRatioBySegment: |
|
(nonnull NCSegment *) | segment1 |
| segment2: |
|
(nonnull NCSegment *) | segment2 |
Calculate the division ratio of a segment by a given segment(if intersects)
- Parameters
-
| segment1 | first segment of calculation Segment |
| segment2 | second segment of calculation Segment |
- Returns
- division ratio
Swift code snippet:
// Calculate division ratio
let divisionRatio = GeometryUtils.divisionRatioBySegment(segment1: segment1, segment2: segment2)
print("Division ratio: \(String(format: "%.2f", divisionRatio))")
Objective C code snippet:
double divisionRatio = [
NCGeometryUtils divisionRatioBySegmentWithSegment1:segment1 segment2:segment2];
NSLog(@"Division ratio: %.2f", divisionRatio);
◆ getProjectionRatio:point:
| + (double) getProjectionRatio: |
|
(nonnull NCSegment *) | segment |
| point: |
|
(nonnull NCPoint *) | point |
Calculate the division ratio of a segment by a given point Calculate projection point on a segment.
- Parameters
-
| segment | segment of calculation Segment |
| point | point of calculation Point |
- Returns
- division ratio
Swift code snippet:
// Calculate projection ratio
let projectionRatio = GeometryUtils.getProjectionRatio(segment: segment1, point: testPoint)
print("Projection ratio: \(String(format: "%.2f", projectionRatio))")
Objective C code snippet:
double projectionRatio = [
NCGeometryUtils getProjectionRatioWithSegment:segment1 point:testPoint];
NSLog(@"Projection ratio: %.2f", projectionRatio);
◆ getRatioPoint:r:
| + (nonnull NCPoint *) getRatioPoint: |
|
(nonnull NCSegment *) | segment |
| r: |
|
(double) | r |
Calculate projection point on a segment.
- Parameters
-
| segment | segment of calculation Segment |
| r | division ratio |
- Returns
- ratio point Point
Swift code snippet:
// Get point at specific ratio
let ratio = 0.5
let ratioPoint = GeometryUtils.getRatioPoint(segment: segment1, r: ratio)
print("Point at ratio \(ratio): (\(String(format: "%.2f", ratioPoint.x)), \(String(format: "%.2f", ratioPoint.y)))")
Objective C code snippet:
double ratio = 0.5;
NCPoint *ratioPoint = [
NCGeometryUtils getRatioPointWithSegment:segment1 r:ratio];
NSLog(
@"Point at ratio %.1f: (%.2f, %.2f)", ratio, ratioPoint.
x, ratioPoint.
y);
◆ polygonArea:
| + (float) polygonArea: |
|
(nonnull NCPolygon *) | polygon |
|
Get polygon area.
- Parameters
-
| polygon | polygon object for calculation Polygon |
- Returns
- area in meters
Swift code snippet:
// Calculate polygon area
let area = GeometryUtils.polygonArea(polygon: polygon)
print("Polygon area: \(String(format: "%.2f", area)) square meters")
Objective C code snippet:
NSLog(@"Polygon area: %.2f square meters", area);
◆ polygonCenter:
Get polygon geometric center.
- Parameters
-
| polygon | polygon object for calculation Polygon |
- Returns
- center point Point
Swift code snippet:
// Calculate polygon center
let center = GeometryUtils.polygonCenter(polygon: polygon)
print("Polygon center: (\(String(format: "%.2f", center.x)), \(String(format: "%.2f", center.y)))")
Objective C code snippet:
NSLog(
@"Polygon center: (%.2f, %.2f)", center.
x, center.
y);
◆ polygonContainsPoint:point:
| + (BOOL) polygonContainsPoint: |
|
(nonnull NCPolygon *) | polygon |
| point: |
|
(nonnull NCPoint *) | point |
Checks that polygon contains point.
- Parameters
-
| polygon | polygon object in which looking for contents Polygon |
| point | checking point object Point |
- Returns
- contains or not
Swift code snippet:
// Check if polygon contains point
let insidePoint = Point(x: 5.0, y: 5.0)
let outsidePoint = Point(x: 15.0, y: 15.0)
let containsInside = GeometryUtils.polygonContainsPoint(polygon: polygon, point: insidePoint)
let containsOutside = GeometryUtils.polygonContainsPoint(polygon: polygon, point: outsidePoint)
print("Polygon contains inside point: \(containsInside)")
print("Polygon contains outside point: \(containsOutside)")
Objective C code snippet:
NCPoint *insidePoint = [[
NCPoint alloc] initWithX:5.0 y:5.0];
NCPoint *outsidePoint = [[
NCPoint alloc] initWithX:15.0 y:15.0];
BOOL containsInside = [
NCGeometryUtils polygonContainsPointWithPolygon:polygon point:insidePoint];
BOOL containsOutside = [
NCGeometryUtils polygonContainsPointWithPolygon:polygon point:outsidePoint];
NSLog(@"Polygon contains inside point: %@", containsInside ? @"YES" : @"NO");
NSLog(@"Polygon contains outside point: %@", containsOutside ? @"YES" : @"NO");
◆ segmentIntersectionSegment:segment2:
Calculate the intersection point of two segments.
- Parameters
-
| segment1 | first segment of calculation Segment |
| segment2 | second segment of calculation Segment |
- Returns
- intersection point Point
Swift code snippet:
// Calculate intersection point
let intersection = GeometryUtils.segmentIntersectionSegment(segment1: segment1, segment2: segment2)
print("Intersection point: (\(String(format: "%.2f", intersection.x)), \(String(format: "%.2f", intersection.y)))")
Objective C code snippet:
NCPoint *intersection = [
NCGeometryUtils segmentIntersectionSegmentWithSegment1:segment1 segment2:segment2];
NSLog(
@"Intersection point: (%.2f, %.2f)", intersection.
x, intersection.
y);
◆ segmentIntersectsSegment:segment2:
| + (BOOL) segmentIntersectsSegment: |
|
(nonnull NCSegment *) | segment1 |
| segment2: |
|
(nonnull NCSegment *) | segment2 |
Checks the intersection of two segments.
- Parameters
-
| segment1 | first segment of calculation Segment |
| segment2 | second segment of calculation Segment |
- Returns
- intersects or not
Swift code snippet:
// Check if segments intersect
let intersects = GeometryUtils.segmentIntersectsSegment(segment1: segment1, segment2: segment2)
print("Segments intersect: \(intersects)")
Objective C code snippet:
BOOL intersects = [
NCGeometryUtils segmentIntersectsSegmentWithSegment1:segment1 segment2:segment2];
NSLog(@"Segments intersect: %@", intersects ? @"YES" : @"NO");
◆ segmentLength:
| + (float) segmentLength: |
|
(nonnull NCSegment *) | segment |
|
Get length of segment.
- Parameters
-
| segment | segment object for calculation Segment |
- Returns
- length in meters
Swift code snippet:
// Calculate segment length
let length1 = GeometryUtils.segmentLength(segment: segment1)
let length2 = GeometryUtils.segmentLength(segment: segment2)
print("Segment1 length: \(String(format: "%.2f", length1)) meters")
print("Segment2 length: \(String(format: "%.2f", length2)) meters")
Objective C code snippet:
NSLog(@"Segment1 length: %.2f meters", length1);
NSLog(@"Segment2 length: %.2f meters", length2);
◆ segmentPointDistance:point:
| + (float) segmentPointDistance: |
|
(nonnull NCSegment *) | segment |
| point: |
|
(nonnull NCPoint *) | point |
Get distance from segment to point.
- Parameters
-
| segment | start segment of calculation Segment |
| point | end point of calculation Point |
- Returns
- distance in meters
Swift code snippet:
// Calculate distance from segment to point
let distanceToPoint = GeometryUtils.segmentPointDistance(segment: segment1, point: testPoint)
print("Distance from segment1 to test point: \(String(format: "%.2f", distanceToPoint)) meters")
Objective C code snippet:
double distanceToPoint = [
NCGeometryUtils segmentPointDistanceWithSegment:segment1 point:testPoint];
NSLog(@"Distance from segment1 to test point: %.2f meters", distanceToPoint);
The documentation for this class was generated from the following file: