Appropriate Transformation for 3D-looking 2D drawi

2019-06-24 14:39发布

问题:

I'm looking for the appropriate transformation to make a 2D image look like a 3D drawing. If I draw a "road" with parallel lines on a sheet of paper, and then tilt the top of the page away from you, so that the road appears to be disappearing into the distance is what I am looking for.

I'm using Java and would like an appropriate API/library. I don't believe "AffineTransformation" accomplishes this.

回答1:

You don't want an AffineTransformation, as that will always preserve parallel lines, which isn't what you want here.

Luckily the Java Advanced Imaging API (javax.media.jai) has exactly what you want, in the shape of the PerspectiveTransform class (click that link for docs).



回答2:

I can't give you a simple answer, but I can tell you that what you're looking to draw is called two-point perspective. With this information, maybe you will be able to find a library that takes a 3D object and produces a perspective view.

Here's a simple Java applet that I've seen previously that demonstrates 2-point perspective: http://mathforum.org/workshops/sum98/participants/sanders/TryPersp.gsp.html

Hope this helps!



回答3:

Your problem is not trivial, but certainly solvable. You can take any four-sided image and apply a 3D perspective transformation. Just don't expect it to be a one-liner.

I'm at home now (checking SO before going to sleep, of course :D), but I'm almost 100% certain this is the site I used to find the appropriate code in C#:

http://ryoushin.com/cmerighi/en-us/61,2007-10-29/Image_Distortion_Enhancements.aspx

Porting it to java should be fairly straightforward. Let me know if the link doesn't solve your answer and I'll edit my answer tomorrow with more info.