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


Python math.tau方法代码示例

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


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

示例1: try_numerical_answer

# 需要导入模块: import math [as 别名]
# 或者: from math import tau [as 别名]
def try_numerical_answer(question: str) -> Optional[Tuple[str, str]]:
    if question.endswith('?') or question.endswith('.') or question.endswith('!'):
        question = question[:-1]
    words = NON_WORD_CHARS.split(question)
    starting_idx = None
    for idx, word in enumerate(words):
        if NUMERICAL_EXPRESSION_STARTER.match(word):
            starting_idx = idx
            break
    if starting_idx is None:
        return
    words = words[starting_idx:]
    length = len(words)
    ending_idx = None
    for idx, word in enumerate(reversed(words)):
        if NUMERICAL_EXPRESSION_ENDER.match("".join(reversed(word))):
            ending_idx = length - idx
            break
    expression = " ".join(words[:ending_idx])
    try:
        result = numexpr.evaluate(expression, local_dict={'pi': math.pi, 'tau': math.tau, 'e': math.e}, global_dict={})
    except Exception:
        return
    return expression, str(result) 
开发者ID:bloomsburyai,项目名称:cape-webservices,代码行数:26,代码来源:utils.py

示例2: cubic_bezier_from_arc

# 需要导入模块: import math [as 别名]
# 或者: from math import tau [as 别名]
def cubic_bezier_from_arc(
        center: Vector = (0, 0), radius: float = 1, start_angle: float = 0, end_angle: float = 360,
        segments: int = 1) -> Iterable[Bezier4P]:
    """
    Returns an approximation for a circular 2D arc by multiple cubic Bézier curves.

    Args:
        center: circle center as :class:`Vector` compatible object
        radius: circle radius
        start_angle: start angle in degrees
        end_angle: end angle in degrees
        segments: count of spline segments, at least one segment for each quarter (90 deg), ``1`` for as few as needed.

    .. versionadded:: 0.13

    """
    center = Vector(center)
    radius = float(radius)
    start_angle = math.radians(start_angle) % math.tau
    end_angle = math.radians(end_angle) % math.tau
    for control_points in cubic_bezier_arc_parameters(start_angle, end_angle, segments):
        defpoints = [center + (p * radius) for p in control_points]
        yield Bezier4P(defpoints) 
开发者ID:mozman,项目名称:ezdxf,代码行数:25,代码来源:bezier4p.py

示例3: cubic_bezier_from_ellipse

# 需要导入模块: import math [as 别名]
# 或者: from math import tau [as 别名]
def cubic_bezier_from_ellipse(ellipse: 'ConstructionEllipse', segments: int = 1) -> Iterable[Bezier4P]:
    """
    Returns an approximation for an elliptic arc by multiple cubic Bézier curves.

    Args:
        ellipse: ellipse parameters as :class:`~ezdxf.math.ConstructionEllipse` object
        segments: count of spline segments, at least one segment for each quarter (pi/2), ``1`` for as few as needed.

    .. versionadded:: 0.13

    """
    from ezdxf.math import param_to_angle
    start_angle = param_to_angle(ellipse.ratio, ellipse.start_param) % math.tau
    end_angle = param_to_angle(ellipse.ratio, ellipse.end_param) % math.tau

    def transform(points: Iterable[Vector]) -> Iterable[Vector]:
        center = Vector(ellipse.center)
        x_axis = ellipse.major_axis
        y_axis = ellipse.minor_axis
        for p in points:
            yield center + x_axis * p.x + y_axis * p.y

    for defpoints in cubic_bezier_arc_parameters(start_angle, end_angle, segments):
        yield Bezier4P(tuple(transform(defpoints))) 
开发者ID:mozman,项目名称:ezdxf,代码行数:26,代码来源:bezier4p.py

示例4: test_swap_axis_arbitrary_params

# 需要导入模块: import math [as 别名]
# 或者: from math import tau [as 别名]
def test_swap_axis_arbitrary_params():
    random_tests_count = 100
    random.seed(0)

    for _ in range(random_tests_count):
        ellipse = ConstructionEllipse(
            # avoid (0, 0, 0) as major axis
            major_axis=(non_zero_random(), non_zero_random(), 0),
            ratio=2,
            start_param=random.uniform(0, math.tau),
            end_param=random.uniform(0, math.tau),
            extrusion=(0, 0, random.choice((1, -1))),
        )

        # Test if coordinates of start- and end point stay at the same location
        # before and after swapping axis.
        start_point = ellipse.start_point
        end_point = ellipse.end_point
        minor_axis = ellipse.minor_axis
        ellipse.swap_axis()
        assert ellipse.major_axis.isclose(minor_axis, abs_tol=1e-9)
        assert ellipse.start_point.isclose(start_point, abs_tol=1e-9)
        assert ellipse.end_point.isclose(end_point, abs_tol=1e-9) 
开发者ID:mozman,项目名称:ezdxf,代码行数:25,代码来源:test_648_construction_ellipse.py

示例5: test_params_from_vertices_random

# 需要导入模块: import math [as 别名]
# 或者: from math import tau [as 别名]
def test_params_from_vertices_random():
    center = Vector.random(5)
    major_axis = Vector.random(5)
    extrusion = Vector.random()
    ratio = 0.75
    e = ConstructionEllipse(center, major_axis, extrusion, ratio)

    params = [random.uniform(0.0001, math.tau - 0.0001) for _ in range(20)]
    vertices = e.vertices(params)
    new_params = e.params_from_vertices(vertices)
    for expected, param in zip(params, new_params):
        assert math.isclose(expected, param)

    # This creates the same vertex as v1 and v2
    v1, v2 = e.vertices([0, math.tau])
    assert v1.isclose(v2)

    # This should create the same param for v1 and v2, but
    # floating point inaccuracy produces unpredictable results:
    p1, p2 = e.params_from_vertices((v1, v2))

    assert math.isclose(p1, 0, abs_tol=1e-9) or math.isclose(p1, math.tau, abs_tol=1e-9)
    assert math.isclose(p2, 0, abs_tol=1e-9) or math.isclose(p2, math.tau, abs_tol=1e-9) 
开发者ID:mozman,项目名称:ezdxf,代码行数:25,代码来源:test_648_construction_ellipse.py

示例6: test_angle_about

# 需要导入模块: import math [as 别名]
# 或者: from math import tau [as 别名]
def test_angle_about():
    extrusion = Vector(0, 0, 1)
    a = Vector(1, 0, 0)
    b = Vector(1, 1, 0)
    assert math.isclose(a.angle_between(b), math.pi / 4)
    assert math.isclose(extrusion.angle_about(a, b), math.pi / 4)

    extrusion = Vector(0, 0, -1)
    assert math.isclose(a.angle_between(b), math.pi / 4)
    assert math.isclose(extrusion.angle_about(a, b), (-math.pi / 4) % math.tau)

    extrusion = Vector(0, 0, 1)
    a = Vector(1, 1, 0)
    b = Vector(1, 1, 0)
    assert math.isclose(a.angle_between(b), 0, abs_tol=1e-5)
    assert math.isclose(extrusion.angle_about(a, b), 0)

    extrusion = Vector(0, 1, 0)
    a = Vector(1, 1, 0)
    b = Vector(0, 1, -1)
    assert math.isclose(a.angle_between(b), math.pi / 3, abs_tol=1e-5)
    c = a.cross(b)
    assert math.isclose(a.angle_between(b), c.angle_about(a, b))
    assert math.isclose(extrusion.angle_about(a, b), math.pi / 2) 
开发者ID:mozman,项目名称:ezdxf,代码行数:26,代码来源:test_602_vector.py

示例7: circle

# 需要导入模块: import math [as 别名]
# 或者: from math import tau [as 别名]
def circle(num_t, radius=1.0, phase=0.0):
    """Returns x and y positions of `num_t` points regularly placed around a circle
    of radius `radius`, shifted by `phase` radians.

    Parameters
    ----------
    num_t : int
        the number of points around the circle
    radius : float, default 1.
        the radius of the circle
    phase : float, default 0.0
        angle shift w/r to the x axis in radians

    Returns
    -------
    points : np.Ndarray of shape (num_t, 2), the x, y positions of the points

    """
    if not num_t:
        return np.zeros((1, 2))

    theta = np.arange(0, tau, tau / num_t)
    return np.vstack([radius * np.cos(theta + phase), radius * np.sin(theta + phase)]).T 
开发者ID:DamCB,项目名称:tyssue,代码行数:25,代码来源:hexagonal_grids.py

示例8: hexa_disk

# 需要导入模块: import math [as 别名]
# 或者: from math import tau [as 别名]
def hexa_disk(num_t, radius=1):
    """Returns an arrays of x, y positions of points evenly spread on
    a disk with num_t points on the periphery.

    Parameters
    ----------
    num_t : int
        the number of poitns on the disk periphery, the rest of the disk is
        filled automaticaly
    radius : float, default 1.
        the radius of the disk

    """

    n_circles = int(np.ceil(num_t / tau) + 1)
    if not n_circles:
        return np.zeros((1, 2))

    num_ts = np.linspace(num_t, 0, n_circles, dtype=int)
    rads = radius * num_ts / num_t
    phases = np.pi * num_ts / num_t
    return np.concatenate(
        [circle(n, r, phi) for n, r, phi in zip(num_ts, rads, phases)]
    ) 
开发者ID:DamCB,项目名称:tyssue,代码行数:26,代码来源:hexagonal_grids.py

示例9: __init__

# 需要导入模块: import math [as 别名]
# 或者: from math import tau [as 别名]
def __init__(self, seed):
        self.rnd = np.random.RandomState(seed)
        self.size = 256
        self.mask = int(self.size - 1)
        self.indices = np.arange(self.size, dtype = np.int16)
        self.rnd.shuffle(self.indices)
        theta = np.linspace(0, math.tau, self.size, endpoint=False)
        self.gradients = [np.cos(theta), np.sin(theta)] 
开发者ID:prideout,项目名称:snowy,代码行数:10,代码来源:noise.py

示例10: groupDelay

# 需要导入模块: import math [as 别名]
# 或者: from math import tau [as 别名]
def groupDelay(data: List[Datapoint], index: int) -> float:
    idx0 = clamp_value(index - 1, 0, len(data) - 1)
    idx1 = clamp_value(index + 1, 0, len(data) - 1)
    delta_angle = data[idx1].phase - data[idx0].phase
    delta_freq = data[idx1].freq - data[idx0].freq
    if delta_freq == 0:
        return 0
    if abs(delta_angle) > math.tau:
        if delta_angle > 0:
            delta_angle = delta_angle % math.tau
        else:
            delta_angle = -1 * (delta_angle % math.tau)
    val = -delta_angle / math.tau / delta_freq
    return val 
开发者ID:NanoVNA-Saver,项目名称:nanovna-saver,代码行数:16,代码来源:RFTools.py

示例11: screen_shake

# 需要导入模块: import math [as 别名]
# 或者: from math import tau [as 别名]
def screen_shake(self, dist=25):
        """Trigger a screen shake effect.

        The camera will be offset from ``.pos`` by ``dist`` in a random
        direction; then steady itself in a damped harmonic motion.

        """
        theta = np.random.uniform(0, math.tau)
        basis = np.array([theta, + math.pi * 0.5])
        self._cam_offset[:] = dist * np.sin(basis)
        self._xform[-1][:2] = self._cam_offset - self._pos
        clock.schedule_unique(self._steady_cam, 0.01) 
开发者ID:lordmauve,项目名称:wasabi2d,代码行数:14,代码来源:scene.py

示例12: girdle_coords

# 需要导入模块: import math [as 别名]
# 或者: from math import tau [as 别名]
def girdle_coords(radius, mat):
    angle = tau / 64

    return tuple(
        (
            mat @ Vector(
                (
                    sin(i * angle) * radius,
                    cos(i * angle) * radius,
                    0.0,
                )
            )
        ).freeze()
        for i in range(64)
    ) 
开发者ID:mrachinskiy,项目名称:jewelcraft,代码行数:17,代码来源:asset.py

示例13: random_angle

# 需要导入模块: import math [as 别名]
# 或者: from math import tau [as 别名]
def random_angle():
    return random.uniform(0, math.tau) 
开发者ID:mozman,项目名称:ezdxf,代码行数:4,代码来源:transformation_workbench.py

示例14: ellipse

# 需要导入模块: import math [as 别名]
# 或者: from math import tau [as 别名]
def ellipse(major_axis=(1, 0), ratio: float = 0.5, start: float = 0, end: float = math.tau, count: int = 8):
    major_axis = Vector(major_axis).replace(z=0)
    ellipse_ = Ellipse.new(dxfattribs={
        'center': (0, 0, 0),
        'major_axis': major_axis,
        'ratio': min(max(ratio, 1e-6), 1),
        'start_param': start,
        'end_param': end
    }, doc=doc)
    control_vertices = list(ellipse_.vertices(ellipse_.params(count)))
    axis_vertices = list(ellipse_.vertices([0, math.pi / 2, math.pi, math.pi * 1.5]))
    return ellipse_, control_vertices, axis_vertices 
开发者ID:mozman,项目名称:ezdxf,代码行数:14,代码来源:transformation_workbench.py

示例15: sine_wave

# 需要导入模块: import math [as 别名]
# 或者: from math import tau [as 别名]
def sine_wave(count: int, scale: float = 1.0):
    for t in linspace(0, math.tau, count):
        yield Vector(t * scale, math.sin(t) * scale) 
开发者ID:mozman,项目名称:ezdxf,代码行数:5,代码来源:spline-end-tangents-estimation.py


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