You'll have to unpeel the transformations applied to B one by one, in reverse order. Typically we'll apply transformations in the sequence...
- Scale
- Euler Roll
- Euler Pitch
- Euler Yaw
- Translate
So going backwards from 5 back to 1 (and assuming the {yaw, pitch, roll} axes are {z, x, y} - I'm not super familiar with Blender's conventions so you might need to swap some):
Untranslated = A.Location - B.Location
Unyawed = Yaw(Untranslated, -B.Rotation.z)
Unpitched = Pitch(Unyawed, -B.Rotation.x)
Unrolled = Roll(Unpitched, -B.Rotation.y)
Unscaled = Scale(Unrolled, (1/B.Scale.x, 1/B.Scale.y, 1/B.Scale.z) )
Now Unscaled
is the point in B's local coordinate space that corresponds to the point A in the global coordinate space.
Here's how we can implement those rotation and scale functions:
(If your sine and cosine functions take their input in radians, be sure to convert your degree inputs to radians first)
Yaw(point, angle) {
s = sin(angle)
c = cos(angle)
return (point.x * c - point.y * s,
point.y * c + point.x * s,
point.z)
}
Pitch(point, angle) {
s = sin(angle)
c = cos(angle)
return (point.x,
point.y * c - point.z * s,
point.z * c + point.y * s)
}
Roll(point, angle) {
s = sin(angle)
c = cos(angle)
return (point.x * c + point.z * s,
point.y,
point.z * c - point.x * s)
}
Scale(point, scaleTriplet) {
return (point.x * scaleTriplet.x,
point.y * scaleTriplet.y,
point.z * scaleTriplet.z)
}