當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。