开发者

3D effect to distort paper

开发者 https://www.devze.com 2022-12-25 23:35 出处:网络
This may be a little hard to describe since I don\'t have a sample. I\'m trying to find a math function or full 3d function in php or a similar language that can help me with the following effect:

This may be a little hard to describe since I don't have a sample. I'm trying to find a math function or full 3d function in php or a similar language that can help me with the following effect:

imagine if you were to take a flat sheet or paper and glue it on a glass of water. It wouldn't be flat any more. It would have a curve, and one of its sides might end up being slightly hidden.

Anyone can refer me to a good library or resource on the web where 开发者_StackOverflow中文版such functions can be found?


Lets say the center of your paper is x=0, and your cylinder is vertical along the y-axis. Your x-coordinate on the paper could be equated to an arc length on the surface of the cylinder. Arc length (s) is equal to the angle (in radians) times the radius. Your radius is given, so you can compute the angle from the arc length and radius. Angle = Arc Length / Radius. Since you now have the angle and the radius, you can compute the new x-offset, which would be (radius * cos(angle)). So your mapping functions would be:

  • new_x = radius * cos(old_x/radius)
  • new_y = old_y; //y-coordinate doesn't change
  • new_z = radius * sin(old_x/radius);

You'll have to enforce boundaries (keep x on the paper, and make sure it's not more than half the circumference (x must be less than or equal to PI*r). Also, watch the signs... especially the z-coordinate, which will depend on whether your coordinate system is right-handed or left-handed, or where you imagine the paper starting on the cylindar (back or front). Finally, you can use standard matrix transforms to move and position the paper/cylinder in 3D space once you have the warped coordinates.

0

精彩评论

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