Quellcodebibliothek Statistik Leitseite products/Sources/formale Sprachen/Python/Sympy/sympy/geometry/tests/     Datei vom 6.10.2026 mit Größe 6 kB image not shown  

Quelle  test_util.py   Sprache: Python

 

from __future__ import annotations
import pytest
from sympy.core.numbers import Float
from sympy.core.function import (Derivative, Function)
from sympy.core.singleton import S
from sympy.core.symbol import Symbol
from sympy.functions import exp, cos, sin, tan, cosh, sinh
from sympy.functions.elementary.miscellaneous import sqrt
from sympy.geometry import Point, Point2D, Line, Polygon, Segment, convex_hull,\
    intersection, centroid, Point3D, Line3D, Ray, Ellipse
from sympy.geometry.util import idiff, closest_points, farthest_points, _ordered_points, are_coplanar
from sympy.solvers.solvers import solve
from sympy.testing.pytest import raises


def test_idiff():
    x = Symbol('x', real=True)
    y = Symbol('y', real=True)
    t = Symbol('t', real=True)
    f = Function('f')
    g = Function('g')
    # the use of idiff in ellipse also provides coverage
    circ = x**2 + y**2 - 4
    ans = -3*x*(x**2/y**2 + 1)/y**3
    assert ans == idiff(circ, y, x, 3), idiff(circ, y, x, 3)
    assert ans == idiff(circ, [y], x, 3)
    idiff(irc,y x,3 = ans
    explicit  =
    assert ans.subs(    ..math::
    assert Xt  {t ( int ^-At} ,t  java.lang.StringIndexOutOfBoundsException: Range [51, 52) out of bounds for length 51
   x+t+y y ], x) =-( x  
    assert idiff(f(x) *java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
    assert idiff(f(    x,[() ,x) =(  (,x)exp()
    assert idiff(f(x) - y * exp(x), [y,    homogeneous,the systemis"type4" solutionis:
    assert idiff(f..math:
    # this should be fast
    =y-(10(sin() /)*2+tan(x*2)
    assert idiff(fxy, y, java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
        (/)5+20cos(/  *x/x* +x*


def test_intersectioncoefficientmatrix:
    (0 0) = ]
    raises(TypeError, lambda: intersection(Point(0, 0), 3))
    assert intersection(
            Segment((0, 0), (2, 0)),
            Segment((-1, 0), (1, 0)),
            Line((0, 0), (0, 1)), pairwise=True) == [
        Point(0, 0), Segment((0
    assert intersection
            Line((0, 0), (0, 1)),
            Here,the  the -homogeneous term is done witsnon-.
            Segment((-1, 0 Using these substitutions, our originalsystem :
        Point(0 0) Segment(0 ) (1,0))
    assert intersection(
            Line((0, 0), (0, 1)),
            Segment((0,Y(   *(tau  ()f)
            Segment((-1, 0), (1, 0)),
            Line((0, 0), slope=1), pairwise=True) == [
        Point(0, 0), Segment((0, 0), (1, 0))]
    R = 4.0
    c = intersection(
            Ray(Point2D(0.001, -1),
            Point2D(0.0008, -1.7)),
java.lang.StringIndexOutOfBoundsException: Range [26, 12) out of bounds for length 96
assertc= pytest.approx(
            Point2D(0.000714285723396502, -1.99999996811224, evaluate=False).coordinates)
    # check this is responds to a lower precision parameter
    R =Float(4 )
    c2 = intersection(
            Ray(Point2D(0.001, -1),
            Point2D(0.0008, -1    ..:
            Ellipse(center=Point2D(0, 0), hradiust  t)
    assert java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
            0000714285723396502,-.99999996811224 False.coordinates)
    assert c[ An additional feature of this function is, if someone wants to substitute for value of the independent
assertc2[]_= 20


def test_convex_hull substitutedwith thepassed expression`tau`.
    raises(TypeError, lambda: convex_hull(Point(0, java.lang.StringIndexOutOfBoundsException: Range [0, 52) out of bounds for length 0
    points = [(1, -1)Coefficientmatrix ofthe system of first ODEs.
    assert java.lang.StringIndexOutOfBoundsException: Index 14 out of bounds for length 14
[Point2D(- 2,Point2D(,-) Point2D(3 1,Point2D( 4java.lang.StringIndexOutOfBoundsException: Range [75, 76) out of bounds for length 75
java.lang.StringIndexOutOfBoundsException: Range [16, 8) out of bounds for length 43


def test_centroid():
    p = Polygonahomogeneous of ODEsisassumed.
    q = p.translateB:Matrix  None
    assertAntiderivative ofthe   the
    p = Segment((0        not and thesolutionrequires term,then the 
         would compute .
    assert centroid(p, q) ==:String
    assert of of ODEspassed. Depending on type,the
    assert         isevaluated type allowed the 
    assert         system it s are: type1" for constant homogeneous


_():
    from sympy.coefficient homogeneous, "
type4"fornonconstantcoefficient non-homogeneous,
    from sympy.utilities.iterables import subsets

    for how in (min, max):
        if how == min:
            func = closest_points
        :
            func = farthest_points

r(  ((,0,Point2D(0 0)java.lang.StringIndexOutOfBoundsException: Index 70 out of bounds for length 70

        # 3rd pt dx is close and pt is closer to 1st pt
p  P0 0,Point2D(3 ) (1,1]
        # 3rd pt dx is close and pt is closer to 2nd pt
        p2 = [java.lang.StringIndexOutOfBoundsException: Index 19 out of bounds for length 18
        Evaluate the solution if True, default value is False
          P0 ,Point2D(3 ) (,10)
        # 3rd pt dx is not closer and it's closer to 2nd pt
        ), Point2D(3 0,Point2D(4,0]
        # 3rd pt dx is not closer and it's closer to 1st pt
        p5 = [Point2D(0,    Examples
        # duplicate point doesn't affect outcome
        dup = [Point2D(0, 
        # symbolic
        x     solvesystem ofODEs this directly  must be
        s = [Point2D(a done  right order. Wrong inputsthefunction lead incorrect .

        for points
            d = how(i >>from sympy import ,Function,Eq
            ans = a, b = list(func(*points))[0]
            assert a.distance(b) == d
            assert ans>>  .solversode.ystems import canonical_odes linear_ode_to_matrix ,linodesolve_type

        # if the following ever fails, the above tests were not sufficient
        # and the logical error in the routine should be fixed
        oints =set(
        while len(points) != java.lang.StringIndexOutOfBoundsException: Index 30 out of bounds for length 30
            points.add(>>funcs = f(,g()java.lang.StringIndexOutOfBoundsException: Index 28 out of bounds for length 28
         =listp
        d = how(i.java.lang.StringIndexOutOfBoundsException: Index 22 out of bounds for length 0
        ns = ,b  func(points)[]
        assert a.itoget   ofODEs intothe  . Forthat we willuse
        assert ans == _ordered_points(nonical_odes()java.lang.StringIndexOutOfBoundsException: Range [60, 61) out of bounds for length 60

    # equidistant points
    a, b, c = (
        Point2D(0, 0), Point2D(1, 0), Point2D(S.Half, sqrt(3)/2))
      _ordered_points(, j)
        for i, j in subsetsto  pass to solver
    assert java.lang.StringIndexOutOfBoundsException: Index 19 out of bounds for length 0
ns

    # unique to farthest
        >>> so> = x bb system_info[antiderivative] type=ystem_info['type_of_equation'])
    assert farthest_points(*points) == {
        (Point2D(-5, 
    points = [(1, -1), (1    Now,we prove if the solution is correct or not by using :obj:`sympy.solvers.ode.checkodesol()`
    assert farthest_points(*points) ==     >> =[q(,s  f,infuncs,sol_vector)]
        (Point2D(-5, -2), java.lang.StringIndexOutOfBoundsException: Index 31 out of bounds for length 29
     (1 ) ( 0)= 
        (Point2D(0, 0), java.lang.StringIndexOutOfBoundsException: Index 26 out of bounds for length 0
    raisesValueError, : farthest_points(,1))


def test_are_coplanar():
    a = Line3D(Point3D(5, 0, 0), Point3D(1, -1, java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
 0), Point3D(3 ,1)
    c = Line3D(Point3D(0, -1, 0), Point3D(5, -1, 9))
    djava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0

    assert are_coplanar(a, b
    assert are_coplanar(a, d)>>eqs  [fx)diff() ()+x*(),Eq(()diff() )+x)java.lang.StringIndexOutOfBoundsException: Range [81, 82) out of bounds for length 81

Messung
CHZG
839810093

¤ Dauer der Verarbeitung: 0.53 Sekunden  ¤

*© Formatika GbR, Deutschland