Created
September 19, 2023 07:01
-
-
Save tvolkert/2de82eaeaaa100c5528c767cbdd5ddb5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:vector_math/vector_math_64.dart'; | |
void main() { | |
Matrix4 transform = Matrix4( | |
1.0, 0.0, 0.0, 0.0, // nodartfmt | |
0.0, 1.0, 0.0, 0.0, // nodartfmt | |
0.0, 0.0, 1.0, 500, // nodartfmt | |
0.0, 0.0, 0.001, 1.5, // nodartfmt | |
); | |
// I want to find the source point that will yield destination point 1305,676 | |
// when the transform is applied. | |
Vector3 points = transform.perspectiveTransform(Vector3(1305, 676, 0)); | |
print('${points.x.truncate()},${points.y.truncate()}'); // 870,450 | |
// So now we know that 1305,676 will transform to 870,450 | |
// ... but what opint will transform to 1305,676? | |
// An inverse transform would seem to make sense... | |
Matrix4 inverse = Matrix4.inverted(transform); | |
Vector3 inversePoints = inverse.perspectiveTransform(Vector3(1305, 676, 0)); | |
print('${inversePoints.x.truncate()},${inversePoints.y.truncate()}'); | |
// wat?? that prints 1305,676, which is the source point! | |
// But we know that the source point transforms to 870,450 | |
// So... what gives? | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment