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


Python Vector.distance方法代码示例

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


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

示例1: createDendrites

# 需要导入模块: import Vector [as 别名]
# 或者: from Vector import distance [as 别名]
    def createDendrites(self):
        angle           = 360.0/self.branches
        startDist       = 0.95 * self.somaSize
        endDist         = startDist + self.stepDist
        halfThickness   = self.dendriteThickness/2.0
        
        a = 0.0
        while a<360.0:
            
            # Define the points that the dendrite would follow if it were a line (i.e. no thickness)
            initialResources = self.maxRadius 
            p1, p2 = Vector(), Vector()
            p1.x = m.cos(m.radians(a)) * startDist + self.center.x
            p1.y = m.sin(m.radians(a)) * startDist + self.center.y
            p2.x = m.cos(m.radians(a)) * endDist + self.center.x
            p2.y = m.sin(m.radians(a)) * endDist + self.center.y
            remainingResources = initialResources - p1.distance(p2)

            # Find the first and last vertex of the quad (moving perpendicular from p1 to create thickness)
            t = p1 - self.center
            leftPerp    = t.leftXYPerpendicular().normalize()
            rightPerp   = t.rightXYPerpendicular().normalize()
            v1 = leftPerp * halfThickness + p1
            v4 = rightPerp * halfThickness + p1

            # Find the second and third vertex of the quad (moving perpendicular from p2 to create thickness)
            t = p2 - p1
            leftPerp    = t.leftXYPerpendicular().normalize()
            rightPerp   = t.rightXYPerpendicular().normalize()
            v2 = leftPerp * halfThickness + p2
            v3 = rightPerp * halfThickness + p2

            # Find the vertex index of the newly added vertices
            startVertexNumber = len(self.verts)
            v1Number = startVertexNumber
            v2Number = startVertexNumber + 1
            v3Number = startVertexNumber + 2
            v4Number = startVertexNumber + 3

            # Add the vertices
            self.verts = self.verts + [v1.toList(), v2.toList(), v3.toList(), v4.toList()]

            # Add a properly ordered face
            face = self.createOrderedQuad(v1, v2, v3, v4, v1Number, v2Number, v3Number, v4Number)
            self.faces.append(face)

            # Store some information about the current dendrite branch
            self.dendrites.append([[a,initialResources,p1,[v1,v1Number],[v4,v4Number]],
                                   [a,remainingResources,p2,[v2,v2Number],[v3,v3Number]]])
            self.lineSegments.append([p1, (p1+p2)/2.0, p2])
            self.updateRadius(v1, v2, v3, v4)
            a += angle
开发者ID:mikewesthad,项目名称:LitWithinBlender,代码行数:54,代码来源:Neuron.py

示例2: Cat

# 需要导入模块: import Vector [as 别名]
# 或者: from Vector import distance [as 别名]
class Cat(Turtle):       #### Inherit behavior from Turtle
    """This turtle walks in a straight line forever.
    >>> from Mouse import *
    >>> from Status import *
    >>> little_mouse = Mouse(Vector(345,350), 1, 1)
    >>> status = Status(Vector(450,350), 1)
    >>> cat = Cat(Vector(800,350), 1 ,little_mouse)
    >>> round(cat.getnextstate()[0].x,3)
    >>> 799.924
    >>> round(cat.getshape()[0].y,3)
    >>> 358.012
    >>> cat.distance_to_r()
    >>> 350.0
    >>> cat.get_cat_degree()
    >>> 0.0
    >>> cat.get_mouse_degree()
    >>> 180.0
    >>> cat.eat_mouse()
    >>> False
    >>> cat.see_the_mouse(cat.get_cat_degree(), cat.get_mouse_degree(), cat.distance_to_r())
    >>> False
    >>> cat.see_the_mouse(35, 396, 100)
    >>> False
    >>> cat.see_the_mouse(0, 45, 810)
    >>> True
    >>> cat.see_the_mouse(150, 240, 810)
    >>> False
    >>> cat.see_the_mouse(0, -57, 400)
    >>> True
    >>> round(cat.rotate()[0].x,3)
    >>> 799.924
    >>> round(cat.towards_circle()[0].x,3)
    >>> 798.333
    """
    Mouse = None
    def __init__(self, position, heading, mouse, fill=yellow, **style):
        '''
        init the cat object and assign the mouse class atttribute
        '''
        Turtle.__init__(self, position, heading, fill=fill,outline=yellow, **style)
        Cat.Mouse = mouse

        self.degree = 0

    def rotate(self):
        '''
        :return rotate 1.25/60 radians per second
        '''
        return self.position.counterclockwise(Vector(450,350), 1.25/60.0), 0

    def towards_circle(self):
        '''
        :return: forward to the status 1/60 meter per second
        '''
        if self.distance_to_r()<=100:
            return self.rotate()
        return self.position + (Vector(450, 350) - self.position).unit()*(100.0/60.0), 0

    def get_cat_degree(self):
        '''
        :return the cat's degree considering the status's coordinate
        '''
        cat_degree = self.position.degree(Vector(450,350))
        self.degree = cat_degree
        return cat_degree

    def get_mouse_degree(self):
        '''
        :return: the mouse's degree considering the status's coordinate
        '''
        mouse_degree = Cat.Mouse.position.degree(Vector(450,350))
        Cat.Mouse.degree = mouse_degree
        return mouse_degree

    def see_the_mouse(self,cat_degree,mouse_degree,r):
        '''
        :return: whether the cat can see the mouse
        '''
        return r * cos(((cat_degree % 360) - (mouse_degree % 360))*pi/180) > 100

    count = 60
    def getnextstate(self):
        '''
        :return next state
        '''
        if self.eat_mouse():
            Cat.Mouse.dead = True
            return self.position, 0

        if self.see_the_mouse(self.get_cat_degree(), self.get_mouse_degree(), self.distance_to_r()):
            if Cat.count == 60:
                Cat.count = 0
        if Cat.count < 60:
            Cat.count += 1
            return self.towards_circle()
        Cat.old_angle = self.get_cat_degree()
        return self.rotate()

    def distance_to_r(self):
        '''
#.........这里部分代码省略.........
开发者ID:xiaoyu-z,项目名称:cat-mouse-Game,代码行数:103,代码来源:Cat.py


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