Wrap an image around a glass
so that it appears rectilinear when viewed straight on


diameter of the glass at the rim:
diameter of the glass at the base:
height of the glass:
thickness of the glass on the sides:
height of the rim of the glass:
height of the bottom of the glass:

redraw the glass

select an image  
then left-click and drag to position the image,
right-click and drag to resize it

wrap it  

compare

 
 
 


  |  






The image on top, printed on plain paper and stuck to the front of the glass.

Printing an image onto a glass so that it appears rectilinear when viewed straight on requires a transformation from the vertical image plane onto the unwrapped surface of the glass.  If the glass is tapered normally (larger at the top), the image will not only be stretched horizontally, but will be bowed upward.  If the glass is larger at the bottom, the bow is inverted.  Projecting the image onto a cylindrical glass is a simpler transformation.

The diameters and height of the glass are the important measurements; the others are just for the display.

The units are arbitrary.

If the image is printed on the back of the glass, refraction starts to play a role at the very edges.

Right-click to save the wrapped image.

Be sure to save the size and position!  Maybe as part of the file name.


Interpolation

(The following images:  original, no interpolation (×1), upsized (×4) then reduced with bicubic, bilinear, reduced bicubic sharpened, bilinear sharpened with the same parameters.  In case you’re wondering, it means “neither rashly nor timidly.”)

Bilinear interpolation reduces resizing artifacts.  It is often disparaged; but properly sharpened, it can be superior to bicubic.

To get bicubic or another interpolation, upscale the projection (×4) then downscale it to 25% in an image editor using that interpolation.  (Don’t judge it by the reduced display on screen; you have to save it then properly reduce it.)

A 3 × 3 inch image printed at 300 ppi would need to be 900 × 900 pixels in size; upscaled, it would be 3600 × 3600, well within the capabilities of modern browsers.


The math

A glass with tapered sides is actually a truncated cone or conical frustum.

The projection of points (x, y) on a vertical plane onto an unwrapped cone (x′, y′ )
(actually, an unwrapped half-cone, as in the front or back half; to include the entire cone, φ = 2 π r/s):

(x, y) α θ s r r = y tan(θ) α = arccos(x/r) s = √(r2 + y2) φ β γ s (x′, y′ ) φ = π r/s β = α (r/s) γ = (π - φ)/2 + β x′ = s cos(γ) y′ = s sin(γ)

The cone angle θ is determined in this case by two radii r0 and r1 and the distance h between them:

r1 r0 θ h θ = arctan((r1 - r0)/h)

Please visit russellcottrell.com | blog