- UID
- 2
- 积分
- 8682
- 帖子
- 2905
- 主题
- 199
- 论坛币
- 11739
- 威望
- 16
- EP值
- 2349
- MP值
- 15
- 阅读权限
- 200
- 注册时间
- 2011-8-3
- 在线时间
- 2597 小时
- 最后登录
- 2024-8-28
|
经测试, 上帖第17行代码 h * cos(ag) 应改为 h / cos(ag), 顺带写了绕Y轴的最近点算法版本.
注: 不管是绕X轴旋转抑或是绕Y轴旋转, 都未考虑进"透视感"(即, 近端变大, 远端变小). 有待升级- from math import cos
- # PIX rotate around x-axis, nearest point approach,
- # the position of PIX is maintained by fixing the middle of the original PIX still
- # point (x, y) maps to a new point (u, v) by the formula u = x, v = y * cos(ag)
- # so destination resolution of PIX is dst_width = src_width, dst_height = src_height * cos(ag)
- def PixRotateX_nearest(PIX, ag):
- src_width = PIX[1][0]
- src_height = PIX[1][1]
- dst_width = src_width
- dst_height = int(src_height * cos(ag) + 0.5)
- PIX_pos = (PIX[0][0], PIX[0][1] + (src_height - dst_height) / 2)
- PIX_res = (dst_width, dst_height)
- size = dst_height * dst_width * 4
- PIX_rgba = [0 for c in range(size)]
- for h in range(dst_height):
- for w in range(dst_width):
- dst_idx = 4 * (h * dst_width + w)
- src_idx = 4 * (int(h / cos(ag) + 0.5) * src_width + w)
- PIX_rgba[dst_idx] = PIX[2][src_idx]
- PIX_rgba[dst_idx + 1] = PIX[2][src_idx + 1]
- PIX_rgba[dst_idx + 2] = PIX[2][src_idx + 2]
- PIX_rgba[dst_idx + 3] = PIX[2][src_idx + 3]
- return (PIX_pos, PIX_res, tuple(PIX_rgba))
- # PIX rotate around y-axis, nearest point approach,
- # the position of PIX is maintained by fixing the middle of the original PIX still
- # point (x, y) maps to a new point (u, v) by the formula u = x * cos(ag), v = y
- # so destination resolution of PIX is dst_width = src_width * cos(ag), dst_height = src_height
- def PixRotateY_nearest(PIX, ag):
- src_width = PIX[1][0]
- src_height = PIX[1][1]
- dst_width = int(src_width * cos(ag) + 0.5)
- dst_height = src_height
- PIX_pos = (PIX[0][0] + (src_width - dst_width) / 2, PIX[0][1])
- PIX_res = (dst_width, dst_height)
- size = dst_height * dst_width * 4
- PIX_rgba = [0 for c in range(size)]
- for h in range(dst_height):
- for w in range(dst_width):
- dst_idx = 4 * (h * dst_width + w)
- src_idx = 4 * (h * src_width + int(w / cos(ag) + 0.5))
- PIX_rgba[dst_idx] = PIX[2][src_idx]
- PIX_rgba[dst_idx + 1] = PIX[2][src_idx + 1]
- PIX_rgba[dst_idx + 2] = PIX[2][src_idx + 2]
- PIX_rgba[dst_idx + 3] = PIX[2][src_idx + 3]
- return (PIX_pos, PIX_res, tuple(PIX_rgba))
复制代码 |
|