Curved Surface Mesh of Cylinder in ThreeJS

Standard

I created this useful function which gets the curved surface of a cylinder. I needed to stick an image on a 3D model of mug, so I created this. Use it like any other Mesh Geometry objects of ThreeJS

THREE.CylinderCurvedSurfaceGeometry = function(radius, height, startAngle, endAngle, horizontalSegments, verticalSegments) {
    var width = radius * 2 * Math.PI;
    var plane = new THREE.PlaneGeometry(width, height, horizontalSegments, verticalSegments);
    var index = 0;

    for(var i=0; i<=verticalSegments; i++) {
        for(var j=0; j<=horizontalSegments; j++) {
            var angle = startAngle + (j/horizontalSegments)*(endAngle - startAngle);
            plane.vertices[index].z = radius * Math.cos(angle);
            plane.vertices[index].x = radius * Math.sin(angle);
            index++;
        }
    }

    return plane;
}

How to use?

mesh = new THREE.Mesh(
            new THREE.CylinderCurvedSurfaceGeometry(58, 100, Math.PI/2, Math.PI, 25, 25),
            new THREE.MeshLambertMaterial({color:'white'})
       );

scene.add(mesh);