当前位置: 首页>>代码示例>>Python>>正文


Python Geometry.clear方法代码示例

本文整理汇总了Python中geometry.Geometry.clear方法的典型用法代码示例。如果您正苦于以下问题:Python Geometry.clear方法的具体用法?Python Geometry.clear怎么用?Python Geometry.clear使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在geometry.Geometry的用法示例。


在下文中一共展示了Geometry.clear方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: from geometry import Geometry [as 别名]
# 或者: from geometry.Geometry import clear [as 别名]
class Sphere:
    """
    Класс для общего описания сферы
    """
    def __init__(self, render_area):
        self.render_area = render_area

        self.approximation_step = 0
        self.radius = 0

        self.projection_name = "default"

        # Координаты источника света
        self.light_x = 0
        self.light_y = 0
        self.light_z = -1000

        self.geom = Geometry()

    def recalculate(self):
        # Настройка шагов аппроксимации
        circle_count = self.approximation_step
        circle_points_count = self.approximation_step + 2

        # Считаем окружность
        self.geom.clear()
        angle_step = 2*math.pi/circle_points_count
        for circle_number in range(0, circle_count):
            radius_for_point_1 = self.radius * math.sqrt(1 - math.pow((circle_count - (circle_number+1))/circle_count, 2))
            z_axis_for_point_1 = self.radius * (circle_count-(circle_number+1))/circle_count

            radius_for_point_2 = self.radius * math.sqrt(1 - math.pow((circle_count - circle_number)/circle_count, 2))
            z_axis_for_point_2 = self.radius * (circle_count - circle_number) / circle_count

            angle = 0
            while angle < 2*math.pi:
                self.geom.points.append(Geometry.from_polar(radius_for_point_1, angle, z_axis_for_point_1))
                self.geom.points.append(Geometry.from_polar(radius_for_point_1, angle+angle_step, z_axis_for_point_1))
                self.geom.edges.append((len(self.geom.points)-2, len(self.geom.points)-1))

                self.geom.points.append(Geometry.from_polar(radius_for_point_2, angle, z_axis_for_point_2))
                self.geom.points.append(Geometry.from_polar(radius_for_point_2, angle+angle_step, z_axis_for_point_2))
                self.geom.edges.append((len(self.geom.points)-2, len(self.geom.points)-1))

                angle += angle_step

            angle = 2*math.pi
            while angle > 0:
                self.geom.points.append(Geometry.from_polar(radius_for_point_1, angle, -z_axis_for_point_1))
                self.geom.points.append(Geometry.from_polar(radius_for_point_1, angle-angle_step, -z_axis_for_point_1))
                self.geom.edges.append((len(self.geom.points)-2, len(self.geom.points)-1))

                self.geom.points.append(Geometry.from_polar(radius_for_point_2, angle, -z_axis_for_point_2))
                self.geom.points.append(Geometry.from_polar(radius_for_point_2, angle-angle_step, -z_axis_for_point_2))
                self.geom.edges.append((len(self.geom.points)-2, len(self.geom.points)-1))

                angle -= angle_step

        for index in range(0, len(self.geom.points), 4):
            self.geom.faces.append((index, index+1, index+3, index+2))

        self.geom.apply_projection(self.projection_name)

    def is_face_visible(self, face):
        """
        Определение видимости грани на основе алгоритма Робертса
        :param face: грань
        :return: True, если видимо, иначе False
        """
        p1_index = face[0]
        x0 = self.geom.points[p1_index][0]
        y0 = self.geom.points[p1_index][1]
        z0 = self.geom.points[p1_index][2]

        p2_index = face[1]
        x1 = self.geom.points[p2_index][0]
        y1 = self.geom.points[p2_index][1]
        z1 = self.geom.points[p2_index][2]

        p3_index = face[2]
        x2 = self.geom.points[p3_index][0]
        y2 = self.geom.points[p3_index][1]
        z2 = self.geom.points[p3_index][2]

        a = y0*(z1 - z2) + y1*(z2 - z0) + y2*(z0 - z1)
        b = z0*(x1 - x2) + z1*(x2 - x0) + z2*(x0 - x1)
        c = x0*(y1 - y2) + x1*(y2 - y0) + x2*(y0 - y1)
        d = -(x0*(y1*z2 - y2*z1) + x1*(y2*z0 - y0*z2) + x2*(y0*z1 - y1*z0))

        """
        Знак result = Ax + By + Cz + D определяет, с какой стороны по отношению к плоскости находится точка s(x,y,z,w).
        Если result > 0, то точка внутри тела
        Если result < 0 - на противаположной стороне, а в случае result = 0 точка принадлежит плоскости.
        """

        s = np.array([[1, 1, -1000, 1]])
        p = np.array([[a],
                      [b],
                      [c],
                      [d]])
#.........这里部分代码省略.........
开发者ID:katya-malyk,项目名称:sphere_approximation,代码行数:103,代码来源:sphere.py


注:本文中的geometry.Geometry.clear方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。