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


Python math.hypot方法代码示例

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


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

示例1: simplifyEdgePixels

# 需要导入模块: import math [as 别名]
# 或者: from math import hypot [as 别名]
def simplifyEdgePixels(pixels, minDistance):
    results = []

    i = 0
    while i < len(pixels):
        results.append((float(pixels[i][0]), float(pixels[i][1])))

        distance = 0
        i2 = i + 1
        while i2 < len(pixels):
            previous = (pixels[i2 - 1][0], pixels[i2 - 1][1])
            current = (pixels[i2][0], pixels[i2][1])
            distance += math.hypot(current[0] - previous[0], current[1] - previous[1])
            if distance > minDistance:
                break
            i2 += 1
        i = i2

    return results 
开发者ID:bitsawer,项目名称:renpy-shader,代码行数:21,代码来源:geometry.py

示例2: containsRegion

# 需要导入模块: import math [as 别名]
# 或者: from math import hypot [as 别名]
def containsRegion(self, otherRegion):
        """
        Check if another region is fully contained in this region.

        Returns
        -------
        True if the other region is fully contained inside this region, and False otherwise.
        """
        from octoprint_excluderegion.RectangularRegion import RectangularRegion

        if (isinstance(otherRegion, RectangularRegion)):
            return (
                self.containsPoint(otherRegion.x1, otherRegion.y1) and
                self.containsPoint(otherRegion.x2, otherRegion.y1) and
                self.containsPoint(otherRegion.x2, otherRegion.y2) and
                self.containsPoint(otherRegion.x1, otherRegion.y2)
            )
        elif (isinstance(otherRegion, CircularRegion)):
            dist = math.hypot(self.cx - otherRegion.cx, self.cy - otherRegion.cy) + otherRegion.r
            return (dist <= self.r)
        else:
            raise ValueError("unexpected type: {otherRegion}".format(otherRegion=otherRegion)) 
开发者ID:bradcfisher,项目名称:OctoPrint-ExcludeRegionPlugin,代码行数:24,代码来源:CircularRegion.py

示例3: dft

# 需要导入模块: import math [as 别名]
# 或者: from math import hypot [as 别名]
def dft(self, data, typecode='h'):
        if type(data) is str:
            a = array.array(typecode, data)
            for index, value in enumerate(a):
                self.real_input[index] = float(value)
        elif type(data) is array.array:
            for index, value in enumerate(data):
                self.real_input[index] = float(value)

        self.fftwf_execute(self.fftwf_plan)

        for i in range(len(self.amplitude)):
            self.amplitude[i] = math.hypot(self.complex_output[i * 2], self.complex_output[i * 2 + 1])
            # self.phase[i] = math.atan2(self.complex_output[i * 2 + 1], self.complex_output[i * 2])

        return self.amplitude  # , self.phase 
开发者ID:respeaker,项目名称:respeaker_python_library,代码行数:18,代码来源:fft.py

示例4: constrainSegmentOffcurves

# 需要导入模块: import math [as 别名]
# 或者: from math import hypot [as 别名]
def constrainSegmentOffcurves(self, a1, h1, h2, a2):
        ax1, ay1 = a1
        hx1, hy1 = h1
        hx2, hy2 = h2
        ax2, ay2 = a2

        ix, iy = self.intersectLineLine(a1, h1, h2, a2)

        if (ix != None) and (iy != None):

            d1 = hypot(hx1-ax1, hy1-ay1)
            di1 = hypot(ix-ax1, iy-ay1)
            if d1 >= di1:
                t1 = atan2(hy1-ay1, hx1-ax1)
                hx1 = ax1 + 0.99*di1*cos(t1)
                hy1 = ay1 + 0.99*di1*sin(t1)

            d2 = hypot(hx2-ax2, hy2-ay2)
            di2 = hypot(ix-ax2, iy-ay2)
            if d2 >= di2:
                t2 = atan2(hy2-ay2, hx2-ax2)
                hx2 = ax2 + 0.99*di2*cos(t2)
                hy2 = ay2 + 0.99*di2*sin(t2)

        return (round(hx1), round(hy1)), (round(hx2), round(hy2)) 
开发者ID:loicsander,项目名称:Robofont-scripts,代码行数:27,代码来源:glyphObjects.py

示例5: add_distances

# 需要导入模块: import math [as 别名]
# 或者: from math import hypot [as 别名]
def add_distances(self, indexes):
        n = len(self.distances)
        for i in indexes:
            if i < 0 or i >= n:
                continue
            j = i + 1
            if self.reverse[i]:
                x1, y1 = self.paths[i][0]
            else:
                x1, y1 = self.paths[i][-1]
            if self.reverse[j]:
                x2, y2 = self.paths[j][-1]
            else:
                x2, y2 = self.paths[j][0]
            self.distances[i] = hypot(x2 - x1, y2 - y1)
            self.total_distance += self.distances[i] 
开发者ID:fogleman,项目名称:xy,代码行数:18,代码来源:planner.py

示例6: pointdistance_pt

# 需要导入模块: import math [as 别名]
# 或者: from math import hypot [as 别名]
def pointdistance_pt(self, x, y):
        result = None
        for p1, p2 in self.successivepoints():
            gx, gy = p2[0] - p1[0], p2[1] - p1[1]
            if gx * gx + gy * gy < 1e-10:
                dx, dy = p1[0] - x, p1[1] - y
            else:
                a = (gx * (x - p1[0]) + gy * (y - p1[1])) / (gx * gx + gy * gy)
                if a < 0:
                    dx, dy = p1[0] - x, p1[1] - y
                elif a > 1:
                    dx, dy = p2[0] - x, p2[1] - y
                else:
                    dx, dy = x - p1[0] - a * gx, y - p1[1] - a * gy
            new = math.hypot(dx, dy)
            if result is None or new < result:
                result = new
        return result 
开发者ID:pyx-project,项目名称:pyx,代码行数:20,代码来源:box.py

示例7: curvature_pt

# 需要导入模块: import math [as 别名]
# 或者: from math import hypot [as 别名]
def curvature_pt(self, params):
        result = []
        # see notes in rotation
        approxarclen = (math.hypot(self.x1_pt-self.x0_pt, self.y1_pt-self.y0_pt) +
                        math.hypot(self.x2_pt-self.x1_pt, self.y2_pt-self.y1_pt) +
                        math.hypot(self.x3_pt-self.x2_pt, self.y3_pt-self.y2_pt))
        for param in params:
            xdot = ( 3 * (1-param)*(1-param) * (-self.x0_pt + self.x1_pt) +
                     6 * (1-param)*param * (-self.x1_pt + self.x2_pt) +
                     3 * param*param * (-self.x2_pt + self.x3_pt) )
            ydot = ( 3 * (1-param)*(1-param) * (-self.y0_pt + self.y1_pt) +
                     6 * (1-param)*param * (-self.y1_pt + self.y2_pt) +
                     3 * param*param * (-self.y2_pt + self.y3_pt) )
            xddot = ( 6 * (1-param) * (self.x0_pt - 2*self.x1_pt + self.x2_pt) +
                      6 * param * (self.x1_pt - 2*self.x2_pt + self.x3_pt) )
            yddot = ( 6 * (1-param) * (self.y0_pt - 2*self.y1_pt + self.y2_pt) +
                      6 * param * (self.y1_pt - 2*self.y2_pt + self.y3_pt) )

            hypot = math.hypot(xdot, ydot)
            result.append((xdot*yddot - ydot*xddot) / hypot**3)
        return result 
开发者ID:pyx-project,项目名称:pyx,代码行数:23,代码来源:normpath.py

示例8: get_markovian_path

# 需要导入模块: import math [as 别名]
# 或者: from math import hypot [as 别名]
def get_markovian_path(points):
    """
    Calculates the shortest path connecting an array of 2D
    points.

    Args:
        points (list): list/array of points of the format
            [[x_1, y_1, z_1], [x_2, y_2, z_2], ...]

    Returns:
        A sorted list of the points in order on the markovian path.
    """

    def dist(x,y):
        return math.hypot(y[0] - x[0], y[1] - x[1])

    paths = [p for p in it.permutations(points)]
    path_distances = [
        sum(map(lambda x: dist(x[0], x[1]), zip(p[:-1], p[1:]))) for p in paths
    ]
    min_index = np.argmin(path_distances)

    return paths[min_index] 
开发者ID:ashtonmv,项目名称:twod_materials,代码行数:25,代码来源:utils.py

示例9: warpImage

# 需要导入模块: import math [as 别名]
# 或者: from math import hypot [as 别名]
def warpImage(src, theta, phi, gamma, scale, fovy):
    halfFovy = fovy * 0.5
    d = math.hypot(src.shape[1], src.shape[0])
    sideLength = scale * d / math.cos(deg2Rad(halfFovy))
    sideLength = np.int32(sideLength)

    M = warpMatrix(src.shape[1], src.shape[0], theta, phi, gamma, scale, fovy)
    dst = cv2.warpPerspective(src, M, (sideLength, sideLength))
    mid_x = mid_y = dst.shape[0] // 2
    target_x = target_y = src.shape[0] // 2
    offset = (target_x % 2)

    if len(dst.shape) == 3:
        dst = dst[mid_y - target_y:mid_y + target_y + offset,
              mid_x - target_x:mid_x + target_x + offset,
              :]
    else:
        dst = dst[mid_y - target_y:mid_y + target_y + offset,
              mid_x - target_x:mid_x + target_x + offset]

    return dst 
开发者ID:timctho,项目名称:convolutional-pose-machines-tensorflow,代码行数:23,代码来源:cpm_utils.py

示例10: update

# 需要导入模块: import math [as 别名]
# 或者: from math import hypot [as 别名]
def update(self, bots):
        px, py = self.position
        tx, ty = self.target
        angle = atan2(ty - py, tx - px)
        dx = cos(angle)
        dy = sin(angle)
        for bot in bots:
            if bot == self:
                continue
            x, y = bot.position
            d = hypot(px - x, py - y) ** 2
            p = bot.padding ** 2
            angle = atan2(py - y, px - x)
            dx += cos(angle) / d * p
            dy += sin(angle) / d * p
        angle = atan2(dy, dx)
        magnitude = hypot(dx, dy)
        self.angle = angle
        return angle, magnitude 
开发者ID:fogleman,项目名称:pg,代码行数:21,代码来源:avoid.py

示例11: get_distance_customers_pair

# 需要导入模块: import math [as 别名]
# 或者: from math import hypot [as 别名]
def get_distance_customers_pair(c1: Customer, c2: Customer) -> float:
    return math.hypot(c2.x - c1.x, c2.y - c1.y) 
开发者ID:shayan-ys,项目名称:VRPTW-ga,代码行数:4,代码来源:nodes.py

示例12: trackDistance

# 需要导入模块: import math [as 别名]
# 或者: from math import hypot [as 别名]
def trackDistance(mPoint1, mPoint2):
    """
    Return the triangulated distance between two tracking locations
    """
    x1, y1 = mPoint1
    x2, y2 = mPoint2
    trackLen = abs(math.hypot(x2 - x1, y2 - y1))
    return trackLen

#------------------------------------------------------------------------------ 
开发者ID:pageauc,项目名称:pi-timolo,代码行数:12,代码来源:pi-timolo.py

示例13: trackDistance

# 需要导入模块: import math [as 别名]
# 或者: from math import hypot [as 别名]
def trackDistance(mPoint1, mPoint2):
    x1, y1 = mPoint1
    x2, y2 = mPoint2
    trackLen = abs(math.hypot(x2 - x1, y2 - y1))
    return trackLen

#----------------------------------------------------------------------------------------------- 
开发者ID:pageauc,项目名称:pi-timolo,代码行数:9,代码来源:pi-timolo81.py

示例14: distance

# 需要导入模块: import math [as 别名]
# 或者: from math import hypot [as 别名]
def distance(x1, y1, x2, y2):
    """Returns the distance between 2 points

    :param x1: x coordinate of point 1
    :param y1: y coordinate of point 1
    :param x2: x coordinate of point 2
    :param y2: y coordinate of point 2
    :return: distance in point units(m)
    """
    return math.hypot(x2 - x1, y2 - y1) 
开发者ID:pydcs,项目名称:dcs,代码行数:12,代码来源:mapping.py

示例15: distance

# 需要导入模块: import math [as 别名]
# 或者: from math import hypot [as 别名]
def distance(self, other):
        """Cartesian distance to other point """
        # only used in triangle.__str__
        return hypot(self.x -other.x, self.y - other.y) 
开发者ID:bitsawer,项目名称:renpy-shader,代码行数:6,代码来源:delaunay.py


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