This content has been marked as final. Show 3 replies
user8929955 wrote:You can't use Affine Transformations to map a rectangle into an arbitrary quadrilateral. Affine Transformations preserve parallelism: so you can only transform a rectangle into another parallelogram.
I'm trying to figure out how to create a transformation to deform a rectangle into a quadrangle, where one corner stays the same. The basic mathematical solution is clear as described in [this Wiki article|http://en.wikipedia.org/wiki/Affine_transformation] .
There are two questions I would like to pose:The API defines Affine Transformations, and then Translations, Scales, Rotations, and Shears. You can (if I remember my Linear Algebra correctly) construct any Affine Transformation by composing translations, scale transformations, rotations, and shears. There's no API for non-affine transformations that I am aware of.
1. Has anyone done this already?
2. Basically this could also be achieved by concatenating simpler transformation (scale, rotation, projection). While scale and rotation is available in JavaFX I wonder how to define projection in a simple way? Projection in this context would mean that I have one edge and then scale the opposing edge in- or outward. This would make a trapeze out of the rectangle. How would such a transformation matrix look like?
Assuming it's a perspective projection you want . . .1 person found this helpful
Do a PerspectiveTransform on your shape.
Or (simplest) enable the PerspectiveCamera on your Scene and set different z co-ordinates for the corners of your shape.
If you want the mathematics behind the perspective camera or want to do perspective calculations to setup your PerspectiveTransform then you can look at:
http://en.wikipedia.org/wiki/Perspective_projection#Perspective_projection (unless you are really keen, just use the simple formula from the Diagram section of the article).
Thanks for your replies, especially the link
was helpful. That was exactly what I was looking for. I then took it one step further, as I needed the transformed shapes to be clickable. I documented this in the following three blog entries:
http://sahits.ch/blog/?p=2286 (JavaFX: Deformation)
http://sahits.ch/blog/?p=2307 (JavaFX: Deformation with offscreen image)
http://sahits.ch/blog/?p=2314 (JavaFX: Perspective Transformation)