开发者

2d to 3d - how to wrap a drawing around a cylinder

开发者 https://www.devze.com 2023-03-05 19:49 出处:网络
I have drawings (arrays of points with x and y coordinates) that are rotated in 3d space: http://www.motiondraw.com/md/as_samples/Testing/_mindreader/main.html

I have drawings (arrays of points with x and y coordinates) that are rotated in 3d space: http://www.motiondraw.com/md/as_samples/Testing/_mindreader/main.html

As it is now, the drawing looks as if wrapped around a cube, with a nasty 90° degree in the corner. Instead it should look as if it were wrapped around a cylinder. Before starting the rotation I call a function (in ActionScript) 'bendDrawing' that for each point sets an initial z-value:

for (var j = 0; j < numPoints; j++ ) {

// drawing开发者_如何学JAVAs are centered – points left of center are < 0 var distFromCenter = Math.abs(shape[i].points[j].x);

var wid = 350;// this could be the radius of the cylinder

// NOTE: suboptimal, as the image gets a 90° corner in the center, at its highest point
// what it should look like: as if the image was wrapped around a cylinder, i.e. in a circular shape
// is that pythagoras? draw triangle, calc distance from base, add to this to c?
var z = wid - distFromCenter;

shape[i].points[j].z =  Math.abs( z);

}

I just can't wrap my head around this ;-) Any pointers much appreciated!

Andreas Weber


try this:

shape[i].points[j].z  = 
    wid * Math.cos((shape[i].points[j].x / wid) * (0.5 * Math.PI));
0

精彩评论

暂无评论...
验证码 换一张
取 消