fork download
  1. import numpy as np
  2. from dataclasses import dataclass
  3. from collections import defaultdict
  4.  
  5. input_points = np.array([
  6. [20., 20., 60.],
  7. [20., 30., 65.],
  8. [55., 30., 80.],
  9. [80., 10., 60.],
  10. [20., 10., 55.],
  11. [60., 30., 70.],
  12. [70., 15., 20.],
  13. ])
  14.  
  15. planes_defined_by_points = [
  16. np.array([[50., 5., 5.], [50., 45., 5.], [70., 45., 95.]]),
  17. np.array([[30., 5., 95.], [30., 45., 95.], [60., 5., 5.]]),
  18. ]
  19.  
  20. @dataclass
  21. class PlaneNormalForm:
  22. """The plane of all points p with np.dot(self.ortho, p) == self.scalar"""
  23. ortho: np.array
  24. scalar: float
  25.  
  26. planes_in_normal_form = []
  27. for points in planes_defined_by_points:
  28. ortho = np.cross(points[1] - points[0],
  29. points[2] - points[0])
  30. planes_in_normal_form.append(PlaneNormalForm(
  31. ortho=ortho,
  32. scalar=np.dot(ortho, points[0])))
  33.  
  34. points_by_relative_position = defaultdict(list)
  35. for point in input_points:
  36. key = tuple(np.dot(plane.ortho, point) > plane.scalar
  37. for plane in planes_in_normal_form)
  38. points_by_relative_position[key].append(point)
  39.  
  40. for key, points in points_by_relative_position.items():
  41. print(key)
  42. for point in points:
  43. print(" {:5.0f}, {:5.0f}, {:5.0f}".format(*point))
  44.  
Success #stdin #stdout 0.29s 28092KB
stdin
Standard input is empty
stdout
(False, True)
     20,    20,    60
     20,    30,    65
     20,    10,    55
(False, False)
     55,    30,    80
     60,    30,    70
(True, False)
     80,    10,    60
     70,    15,    20