Loading...
Searching...
No Matches

A set of functions for working with geometries. More...

#include <com/navigine/idl/objc/NCGeometryUtils.h>

Inherits NSObject.

Class Methods

(float) + distanceBetweenGlobalPoints:to:
 Get distance between GPS points.
 
(float) + distanceBetweenPoints:to:
 Get distance between points.
 
(float) + segmentLength:
 Get length of segment.
 
(float) + polygonArea:
 Get polygon area.
 
(nonnull NCPoint *) + polygonCenter:
 Get polygon geometric center.
 
(BOOL) + polygonContainsPoint:point:
 Checks that polygon contains point.
 
(float) + segmentPointDistance:point:
 Get distance from segment to point.
 
(BOOL) + segmentIntersectsSegment:segment2:
 Checks the intersection of two segments.
 
(nonnull NCPoint *) + segmentIntersectionSegment:segment2:
 Calculate the intersection point of two segments.
 
(float) + divisionRatioBySegment:segment2:
 Calculate the division ratio of a segment by a given segment(if intersects)
 
(nonnull NCPoint *) + getRatioPoint:r:
 Calculate projection point on a segment.
 
(double) + getProjectionRatio:point:
 Calculate the division ratio of a segment by a given point Calculate projection point on a segment.
 

Properties

BOOL valid
 

Detailed Description

A set of functions for working with geometries.

Definition at line 21 of file NCGeometryUtils.h.

Method Documentation

◆ distanceBetweenGlobalPoints:to:

+ (float) distanceBetweenGlobalPoints: (nonnull NCGlobalPoint *) from
to: (nonnull NCGlobalPoint *) to 

Get distance between GPS points.

Parameters
fromstart point of calculation GlobalPoint
toend point of calculation GlobalPoint
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:

// Calculate distance between global points
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
fromstart point of calculation Point
toend 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:

// Calculate distance between points
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
segment1first segment of calculation Segment
segment2second 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:

// Calculate division ratio
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
segmentsegment of calculation Segment
pointpoint 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:

// Calculate projection ratio
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
segmentsegment of calculation Segment
rdivision 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:

// Get point at specific ratio
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
polygonpolygon 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:

// Calculate polygon area
double area = [NCGeometryUtils polygonAreaWithPolygon:polygon];
NSLog(@"Polygon area: %.2f square meters", area);

◆ polygonCenter:

+ (nonnull NCPoint *) polygonCenter: (nonnull NCPolygon *) polygon

Get polygon geometric center.

Parameters
polygonpolygon 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:

// Calculate polygon center
NCPoint *center = [NCGeometryUtils polygonCenterWithPolygon:polygon];
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
polygonpolygon object in which looking for contents Polygon
pointchecking 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:

// Check if polygon contains point
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:

+ (nonnull NCPoint *) segmentIntersectionSegment: (nonnull NCSegment *) segment1
segment2: (nonnull NCSegment *) segment2 

Calculate the intersection point of two segments.

Parameters
segment1first segment of calculation Segment
segment2second 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:

// Calculate intersection point
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
segment1first segment of calculation Segment
segment2second 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:

// Check if segments intersect
BOOL intersects = [NCGeometryUtils segmentIntersectsSegmentWithSegment1:segment1 segment2:segment2];
NSLog(@"Segments intersect: %@", intersects ? @"YES" : @"NO");

◆ segmentLength:

+ (float) segmentLength: (nonnull NCSegment *) segment

Get length of segment.

Parameters
segmentsegment 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:

// Calculate segment length
double length1 = [NCGeometryUtils segmentLengthWithSegment:segment1];
double length2 = [NCGeometryUtils segmentLengthWithSegment:segment2];
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
segmentstart segment of calculation Segment
pointend 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:

// Calculate distance from segment to point
double distanceToPoint = [NCGeometryUtils segmentPointDistanceWithSegment:segment1 point:testPoint];
NSLog(@"Distance from segment1 to test point: %.2f meters", distanceToPoint);

Property Documentation

◆ valid

- (BOOL) valid
readnonatomicassign

Tells if this object is valid or not. Any method called on an invalid object will throw an exception. The object becomes invalid only on UI thread, and only when its implementation depends on objects already destroyed by now.

Definition at line 252 of file NCGeometryUtils.h.


The documentation for this class was generated from the following file: