I have a few coordinates that form a triangle. I have a relative point to that triangle. if the coordinates get translated to a new triangle I want to calculate the new relative point. How do I do this generally not only for 2 dimensions but for larger ones too?
# triangle translation
(5, 2) -> (2, -3)
(2, -3) -> (-3, 6)
(-3, 6) -> (6, 5)
# relative point
(5, -7) -> (x, y)
how do I solve for x, y?
EDIT: as I've done more research into basic geometric transformations I can see that I'm asking for a generalization of all possible transformations of the space. This is not merely a rotation, or a dilation, etc. This particular example rotates the space then stretches it in various ways. So what is the generalized solution for calculating spatial transformations? What are the steps to solve for X?
EDIT AGAIN: thinking about this intuitively I think there might be two answers to the question: one where the 2d space is not rotated and one where it is.
I think the first, straightforward solution is the one I'm looking for. But I don't know how to compute it. But if the case can be made that the second rotational solution is more generalized maybe I'd rather use that, idk. I think I'd be happy with either solution.
Can you help me?
Additional Edit:
Here is the starter code I have produced from John Hughes linear transformation calculation below.
def extrapolate(domain_coordinates, result_coordinates, point):
'''
given a set of input coordinates and their resulting
coordinates post-transformation, and given an additional
input coordinate return the location (coordinate) in the
post-transformation space that corresponds to the most
logical linear transformation of that space for that
additional point. "extrapolate where this point ends up"
'''
import numpy as np
# Add the number 1 to the coordinates for each point
domain = [(x, y, 1) for x, y in domain_coordinates]
# Do the same for the "target" coordinates too
result = [(x, y, 1) for x, y in result_coordinates]
# Put these coordinates, arranged vertically, into a 3×3 matrix
domain = np.array(domain).T
result = np.array(result).T
# D^−1 is the "matrix inverse"
inverse = np.linalg.inv(domain)
# Let M=RD^−1
matrix = result * inverse # why do I need M?...
# Do the same for the extrapolation point
xpoint = [(x, y, 1) for x, y in [point]]
xpoint = np.array(xpoint).T
# extrapolate ???
extrapolated_point = matrix * xpoint # this isn't right...
return extrapolated_point
extrapolate(
domain_coordinates=[(5, 2), (2, -3), (-3, 6)],
result_coordinates=[(2, -3), (-3, 6), (6, 5)],
point=(5, -7))
This code is not working right, for instance, if I insert this test just before the return...
print(domain * np.array([[1],[0],[0]]).T)
print(domain * np.array([[1],[0],[0]]).T * matrix)
it prints...
[[5 0 0]
[2 0 0]
[1 0 0]]
[[ 1.73076923 0. -0.]
[-0.57692308 -0. 0.]
[-0.34615385 0. 0.]]
whereas I would expect it to print...
[[5 0 0]
[2 0 0]
[1 0 0]]
[[ 2 0. 0.]
[-3 0. 0.]
[-1 0. 0.]]
as per this statement:
Then multiplication by the matrix R will take A to A′
Can you show me where I've gone wrong?


