ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

2021-07-04学习总结

2021-07-07 21:32:05  阅读:223  来源: 互联网

标签:voxel last 07 04 countinue current 2021 tMaxX voxels


菜鸡学Python——学习总结

关于2021.7.4的python编译的学习总结
链接: https://blog.csdn.net/river_rain/article/details/113856897?spm=1001.2014.3001.5501.

用切片法创建列表副本

这其实是python编译的基本功,然而实战中却忘了。

 visited_voxels.append(current_voxel)

此处会将列表current_voxel的地址作为参数,由于在循环中会不断地使用该语句来将新数据放入列表visited_voxels中,会导致visited_voxels中的每一个元素都是current_voxel的地址。所以应该这么写:

 visited_voxels.append(current_voxel[:])

现在才是创立了current_voxel的副本,将其中的元素放入visited_voxels

用函数调用解决臃肿

...
 countinue = 0
    for i in range(0,len(last_voxel)):
        if last_voxel[i] != current_voxel[i]:
            countinue = 1
    while countinue:
        if tMaxX < tMaxY:
            if tMaxX < tMaxZ:
                current_voxel[0] += stepX
                tMaxX += tDeltaX
            else:
                current_voxel[2] += stepZ
                tMaxX += tDeltaZ
        else:
            if tMaxY < tMaxZ:
                current_voxel[1] += stepY
                tMaxY += tDeltaY
            else:
                current_voxel[2] += stepZ
                tMaxZ += tDeltaZ

        visited_voxels.append(current_voxel[:])
       
        countinue = 0
        for i in range(0,len(last_voxel)):
            if last_voxel[i] != current_voxel[i]:
                countinue = 1

这段不美观且有重复性内容,应用函数调用的方式来简化

 def loop(last_voxel,current_voxel):
    
    countinue = 0
    for i in range(0,len(last_voxel)):
        if last_voxel[i] != current_voxel[i]:
            countinue = 1
    return countinue
 ...   
 while loop(last_voxel[:],current_voxel[:]):
        if tMaxX < tMaxY:
            if tMaxX < tMaxZ:
                current_voxel[0] += stepX
                tMaxX += tDeltaX
            else:
                current_voxel[2] += stepZ
                tMaxX += tDeltaZ
        else:
            if tMaxY < tMaxZ:
                current_voxel[1] += stepY
                tMaxY += tDeltaY
            else:
                current_voxel[2] += stepZ
                tMaxZ += tDeltaZ

        visited_voxels.append(current_voxel[:])

编译环境的不同

笔者当时是用的VS来编译的,此处的DBL_MAX因为并没用被实际使用所以没有报错,程序也可以正常运行,但笔者的朋友却是用的pycharm,DBL_MAX因为没有实际赋值而报错。这种编译环境的问题以后需要注意,可能会引发交接问题:“为什么我的电脑可以运行,你的不能?”

tMaxX = ((int(next_voxel_boundary_x) - ray_start[0])/ray[0] if ray[0] != 0 else DBL_MAX)

标签:voxel,last,07,04,countinue,current,2021,tMaxX,voxels
来源: https://blog.csdn.net/river_rain/article/details/118557091

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有