0

Python: How to reflect several (if not many) n dimensional points in two lines, one after another, which are defined by two n dimensional coordinates each.

Given several n dimensional points,

eg P1 = (4, 3, 2, 5, 7) P2 = (7, 3, 2, 2, 3),

and two n dimensional points for each of the two lines of reflections,

eg L1P1 = (5, 6, 4, 3, 2) L1P2 = (7, 6, 9, 8, 1) L2P1 = (1, 3, 4, 9, 2) L2P2 = (5, 4, 3, 7, 6),

reflect the points which don't define lines, in this case P1 and P2, in the first line and then the second and return the coordinates of every double reflected point.

I'm fairly new to this sort of maths, and can't get anything to work that achieves this. I started out trying to achieve n dimensional rotation, given the angle of rotation for each axis, but quickly realised that was too difficult for the scope of my project. I switched to attempting nd reflections by iterating through each point and finding its intersection with the line of reflection, so that I could extend the imaginary line between the intersection and the given point across the other side of the line to create the new, reflected point. I assumed this isn't the most efficient way to tackle the problem, and couldn't find much online about finding the coordinates of the intersection rather than the distance, which is why I'm asking this - to see if anyone can help provide an all-in-one solution.

I'm using Python 3.7 and can use any package, although popular ones are preferable - efficiency is most important though.

Any tips appreciated, thanks!

1 Answers1

0

We have to calculate point S, having point P and line AB

enter image description here

At first define vectors

AP = P - A
AB = B - A

N is projection of P onto AB line, we calculate it using dot (scalar) product of vectors:

AN = AB * Dot(AP, AB) / Dot(AB, AB)

Difference

PN = AB * Dot(AP, AB) / Dot(AB, AB) - AP

Symmetrical (reflected) point

S = P + 2 * PN  = 
    P + 2 * AB * Dot(AP, AB) / Dot(AB, AB) - 2 * AP

Example is in 2D, but this approach works in n-dimensional case as well.

MBo
  • 77,366
  • 5
  • 53
  • 86