2021-06-22 13:16:17 -04:00
|
|
|
"""
|
|
|
|
Point module
|
|
|
|
SPDX - License - Identifier: LGPL - 3.0 - or -later
|
|
|
|
Copyright © 2020 Project Author Pilar Monsalvete Alvarez de Uribarri pilar.monsalvete@concordia.ca
|
|
|
|
"""
|
|
|
|
|
|
|
|
import math
|
|
|
|
|
|
|
|
|
|
|
|
class Point:
|
|
|
|
"""
|
|
|
|
Point class
|
|
|
|
"""
|
|
|
|
|
|
|
|
def __init__(self, coordinates):
|
|
|
|
self._coordinates = coordinates
|
|
|
|
|
|
|
|
@property
|
|
|
|
def coordinates(self):
|
2021-08-26 09:19:38 -04:00
|
|
|
"""
|
|
|
|
Point coordinates
|
|
|
|
"""
|
2021-06-22 13:16:17 -04:00
|
|
|
return self._coordinates
|
|
|
|
|
|
|
|
def distance_to_point(self, other_point):
|
|
|
|
"""
|
|
|
|
distance between points in an n-D Euclidean space
|
|
|
|
:param other_point: point or vertex
|
|
|
|
:return: float
|
|
|
|
"""
|
|
|
|
power = 0
|
|
|
|
for dimension in range(0, len(self.coordinates)):
|
|
|
|
power += math.pow(other_point.coordinates[dimension]-self.coordinates[dimension], 2)
|
|
|
|
distance = math.sqrt(power)
|
|
|
|
return distance
|