o
    oh                     @   s   d Z ddlmZmZ ddlmZ ddlmZ ddlm	Z	 ddl
mZ ddlmZ ddlmZmZ dd	lmZ dd
lmZ ddlmZ ddlZddlmZ ddlmZ ddlmZ ddlmZmZ ddgiZ edddgidZ!G dd dZ"dS )zB
This module can be used to solve problems related
to 2D Trusses.
    )ataninf)Add)INF)Mul)Symbol)sympify)Matrixpi)import_module)sqrt)zerosN)Quantity)plot)doctest_depends_on)sincos
Truss.draw
matplotlibnumpyfromlistarange)import_kwargsc                   @   s  e Zd ZdZdd Zedd Zedd Zedd	 Zed
d Z	edd Z
edd Zedd Zedd Zedd Zdd Zdd Zdd Zdd Zdd Zd d! Zd"d# Zd$d% Zd&d' Zd(d) Zd*d+ Zed,d-d9d/d0Zd1d2 Zd3d4 Zd5d6 Zd7d8 Zd.S ):TrussaZ  
    A Truss is an assembly of members such as beams,
    connected by nodes, that create a rigid structure.
    In engineering, a truss is a structure that
    consists of two-force members only.

    Trusses are extremely important in engineering applications
    and can be seen in numerous real-world applications like bridges.

    Examples
    ========

    There is a Truss consisting of four nodes and five
    members connecting the nodes. A force P acts
    downward on the node D and there also exist pinned
    and roller joints on the nodes A and B respectively.

    .. image:: truss_example.png

    >>> from sympy.physics.continuum_mechanics.truss import Truss
    >>> t = Truss()
    >>> t.add_node(("node_1", 0, 0), ("node_2", 6, 0), ("node_3", 2, 2), ("node_4", 2, 0))
    >>> t.add_member(("member_1", "node_1", "node_4"), ("member_2", "node_2", "node_4"), ("member_3", "node_1", "node_3"))
    >>> t.add_member(("member_4", "node_2", "node_3"), ("member_5", "node_3", "node_4"))
    >>> t.apply_load(("node_4", 10, 270))
    >>> t.apply_support(("node_1", "pinned"), ("node_2", "roller"))
    c                 C   sR   g | _ i | _i | _i | _g | _g | _g | _g | _i | _i | _	i | _
i | _i | _dS )z'
        Initializes the class
        N)_nodes_members_loads	_supports_node_labels_node_positions_node_position_x_node_position_y_nodes_occupied_member_lengths_reaction_loads_internal_forces_node_coordinatesself r)   {/var/www/html/construction_image-detection-poc/venv/lib/python3.10/site-packages/sympy/physics/continuum_mechanics/truss.py__init__;   s   
zTruss.__init__c                 C      | j S )zL
        Returns the nodes of the truss along with their positions.
        )r   r'   r)   r)   r*   nodesM      zTruss.nodesc                 C   r,   )z7
        Returns the node labels of the truss.
        )r   r'   r)   r)   r*   node_labelsT   r.   zTruss.node_labelsc                 C   r,   )zB
        Returns the positions of the nodes of the truss.
        )r   r'   r)   r)   r*   node_positions[   r.   zTruss.node_positionsc                 C   r,   )zW
        Returns the members of the truss along with the start and end points.
        )r   r'   r)   r)   r*   membersb   r.   zTruss.membersc                 C   r,   )zA
        Returns the length of each member of the truss.
        )r#   r'   r)   r)   r*   member_lengthsi   r.   zTruss.member_lengthsc                 C   r,   )z
        Returns the nodes with provided supports along with the kind of support provided i.e.
        pinned or roller.
        )r   r'   r)   r)   r*   supportsp   s   zTruss.supportsc                 C   r,   )z8
        Returns the loads acting on the truss.
        )r   r'   r)   r)   r*   loadsx   r.   zTruss.loadsc                 C   r,   )z^
        Returns the reaction forces for all supports which are all initialized to 0.
        )r$   r'   r)   r)   r*   reaction_loads   r.   zTruss.reaction_loadsc                 C   r,   )z]
        Returns the internal forces for all members which are all initialized to 0.
        )r%   r'   r)   r)   r*   internal_forces   r.   zTruss.internal_forcesc                 G   s   |D ]V}|d }|d }t |}|d }t |}|| jv r!td||g| j v r.td| j|||f | j| | j||f | j| | j	| ||g| j|< qdS )ak  
        This method adds a node to the truss along with its name/label and its location.
        Multiple nodes can be added at the same time.

        Parameters
        ==========
        The input(s) for this method are tuples of the form (label, x, y).

        label:  String or a Symbol
            The label for a node. It is the only way to identify a particular node.

        x: Sympifyable
            The x-coordinate of the position of the node.

        y: Sympifyable
            The y-coordinate of the position of the node.

        Examples
        ========

        >>> from sympy.physics.continuum_mechanics.truss import Truss
        >>> t = Truss()
        >>> t.add_node(('A', 0, 0))
        >>> t.nodes
        [('A', 0, 0)]
        >>> t.add_node(('B', 3, 0), ('C', 4, 1))
        >>> t.nodes
        [('A', 0, 0), ('B', 3, 0), ('C', 4, 1)]
        r         z!Node needs to have a unique labelz+A node already exists at the given positionN)
r   r&   
ValueErrorvaluesr   appendr   r   r    r!   )r(   argsilabelxyr)   r)   r*   add_node   s"   
zTruss.add_nodec                 G   s  |D ]}t t| jD ]}| j| |kr| j| }| j| }q|| jvr(td| j	 }|D ]}|| j| d ksC|| j| d krGtdq/| j
|||f | j| | j||f | j| | j| || jv rv| j| || jv r| j| | j| qdS )a  
        This method removes a node from the truss.
        Multiple nodes can be removed at the same time.

        Parameters
        ==========
        The input(s) for this method are the labels of the nodes to be removed.

        label:  String or Symbol
            The label of the node to be removed.

        Examples
        ========

        >>> from sympy.physics.continuum_mechanics.truss import Truss
        >>> t = Truss()
        >>> t.add_node(('A', 0, 0), ('B', 3, 0), ('C', 5, 0))
        >>> t.nodes
        [('A', 0, 0), ('B', 3, 0), ('C', 5, 0)]
        >>> t.remove_node('A', 'C')
        >>> t.nodes
        [('B', 3, 0)]
        z No such node exists in the trussr   r7   z0The given node already has member attached to itN)rangelenr-   r   r    r!   r&   r9   r   copyr   remover   r   popr   )r(   r<   r>   r=   r?   r@   members_duplicatememberr)   r)   r*   remove_node   s0   



$

zTruss.remove_nodec                 G   s   |D ]t}|d }|d }|d }|| j vs|| j vs||kr"td|| jv r+td| j||fr7td||g| j|< t| j | d | j | d  d | j | d | j | d  d  | j|< d| j||f< d| j||f< d| j|< qdS )	aD  
        This method adds a member between any two nodes in the given truss.

        Parameters
        ==========
        The input(s) of the method are tuple(s) of the form (label, start, end).

        label: String or Symbol
            The label for a member. It is the only way to identify a particular member.

        start: String or Symbol
            The label of the starting point/node of the member.

        end: String or Symbol
            The label of the ending point/node of the member.

        Examples
        ========

        >>> from sympy.physics.continuum_mechanics.truss import Truss
        >>> t = Truss()
        >>> t.add_node(('A', 0, 0), ('B', 3, 0), ('C', 2, 2))
        >>> t.add_member(('AB', 'A', 'B'), ('BC', 'B', 'C'))
        >>> t.members
        {'AB': ['A', 'B'], 'BC': ['B', 'C']}
        r   r7   r8   z;The start and end points of the member must be unique nodesz9A member with the same label already exists for the trussz-A member already exists between the two nodesTN)r&   r9   r   r"   getr   r#   r%   )r(   r<   r=   r>   startendr)   r)   r*   
add_member   s    
JzTruss.add_memberc                 G   s   |D ]A}|| j vrtd| j| j | d | j | d f | j| j | d | j | d f | j | | j| | j| qdS )a|  
        This method removes members from the given truss.

        Parameters
        ==========
        labels: String or Symbol
            The label for the member to be removed.

        Examples
        ========

        >>> from sympy.physics.continuum_mechanics.truss import Truss
        >>> t = Truss()
        >>> t.add_node(('A', 0, 0), ('B', 3, 0), ('C', 2, 2))
        >>> t.add_member(('AB', 'A', 'B'), ('AC', 'A', 'C'), ('BC', 'B', 'C'))
        >>> t.members
        {'AB': ['A', 'B'], 'AC': ['A', 'C'], 'BC': ['B', 'C']}
        >>> t.remove_member('AC', 'BC')
        >>> t.members
        {'AB': ['A', 'B']}
        z"No such member exists in the Trussr   r7   N)r   r9   r"   rF   r#   r%   )r(   r<   r>   r)   r)   r*   remove_member%  s   
$$zTruss.remove_memberc              
   G   s  |D ]c}|d }|d }|| j vrtd|| j v rtd| jD ]B}|d |kre||d |d f| j| j||d |d f< || j| j|d < | j | | j |< | j | |d | jv ru| j|d  | j|< | j|d  || jv r| j| dkrgdt| d | jv rdt| d	 | jv r| jdt| d  | jdt| d < | jdt| d	  | jdt| d	 < | jdt| d  | jdt| d	  | j	| | j	|< | j	| D ]*}|d d
kr|d  t
dt| d	 8  < |d dkr| j	| |  nq| j	| D ]+}|d dkr@|d  t
dt| d 8  < |d dkr>| j	| |  nq| |t
dt| d d | |t
dt| d	 d
 | j	| nk| j| dkr| j	| | j	|< | j	| D ]+}|d d
kr|d  t
dt| d	 8  < |d dkr| j	| |  nq|| |t
dt| d	 d
 | j	| n|| j	v r| j	| | j	|< | j	| | jD ]}| j| d |d kr|| j| d< d| j|| j| d f< d| j| j| d |f< | j|| j| d f | j| j| d |f q| j| d |d krc|| j| d< d| j| j| d |f< d| j|| j| d f< | j| j| d |f | j|| j| d f qq"qdS )a  
        This method changes the label(s) of the specified node(s).

        Parameters
        ==========
        The input(s) of this method are tuple(s) of the form (label, new_label).

        label: String or Symbol
            The label of the node for which the label has
            to be changed.

        new_label: String or Symbol
            The new label of the node.

        Examples
        ========

        >>> from sympy.physics.continuum_mechanics.truss import Truss
        >>> t = Truss()
        >>> t.add_node(('A', 0, 0), ('B', 3, 0))
        >>> t.nodes
        [('A', 0, 0), ('B', 3, 0)]
        >>> t.change_node_label(('A', 'C'), ('B', 'D'))
        >>> t.nodes
        [('C', 0, 0), ('D', 3, 0)]
        r   r7   z!No such node exists for the Trussz*A node with the given label already existsr8   pinnedR__x_yZ   rollerTN)r&   r9   r   indexr   rF   r   strr$   r   r   rE   
apply_loadr   r"   )r(   r<   r=   r>   	new_labelnodeloadrH   r)   r)   r*   change_node_labelF  s   


.,((   
zTruss.change_node_labelc                 G   s   |D ]V}|d }|d }|| j vrtdt| j  }|D ]9}||krW| j | d | j | d g| j |< | j | | j| | j|< | j| | j| | j|< | j| qqdS )a  
        This method changes the label(s) of the specified member(s).

        Parameters
        ==========
        The input(s) of this method are tuple(s) of the form (label, new_label)

        label: String or Symbol
            The label of the member for which the label has
            to be changed.

        new_label: String or Symbol
            The new label of the member.

        Examples
        ========

        >>> from sympy.physics.continuum_mechanics.truss import Truss
        >>> t = Truss()
        >>> t.add_node(('A', 0, 0), ('B', 3, 0), ('D', 5, 0))
        >>> t.nodes
        [('A', 0, 0), ('B', 3, 0), ('D', 5, 0)]
        >>> t.change_node_label(('A', 'C'))
        >>> t.nodes
        [('C', 0, 0), ('B', 3, 0), ('D', 5, 0)]
        >>> t.add_member(('BC', 'B', 'C'), ('BD', 'B', 'D'))
        >>> t.members
        {'BC': ['B', 'C'], 'BD': ['B', 'D']}
        >>> t.change_member_label(('BC', 'BC_new'), ('BD', 'BD_new'))
        >>> t.members
        {'BC_new': ['B', 'C'], 'BD_new': ['B', 'D']}
        r   r7   z#No such member exists for the TrussN)r   r9   listrD   rF   r#   r%   )r(   r<   r=   r>   rX   rG   rH   r)   r)   r*   change_member_label  s"   !
"zTruss.change_member_labelc                 G   sx   |D ]7}|d }|d }|d }t |}t |}|| jvr!td|| jv r1| j| ||g q||gg| j|< qdS )a?  
        This method applies external load(s) at the specified node(s).

        Parameters
        ==========
        The input(s) of the method are tuple(s) of the form (location, magnitude, direction).

        location: String or Symbol
            Label of the Node at which load is applied.

        magnitude: Sympifyable
            Magnitude of the load applied. It must always be positive and any changes in
            the direction of the load are not reflected here.

        direction: Sympifyable
            The angle, in degrees, that the load vector makes with the horizontal
            in the counter-clockwise direction. It takes the values 0 to 360,
            inclusive.

        Examples
        ========

        >>> from sympy.physics.continuum_mechanics.truss import Truss
        >>> from sympy import symbols
        >>> t = Truss()
        >>> t.add_node(('A', 0, 0), ('B', 3, 0))
        >>> P = symbols('P')
        >>> t.apply_load(('A', P, 90), ('A', P/2, 45), ('A', P/4, 90))
        >>> t.loads
        {'A': [[P, 90], [P/2, 45], [P/4, 90]]}
        r   r7   r8   z$Load must be applied at a known nodeN)r   r&   r9   r   r;   r(   r<   r=   location	magnitude	directionr)   r)   r*   rW     s    

zTruss.apply_loadc                 G   s   |D ]C}|d }|d }|d }t |}t |}|| jvr!td||g| j| vr.td| j| ||g | j| g krE| j| qdS )ad  
        This method removes already
        present external load(s) at specified node(s).

        Parameters
        ==========
        The input(s) of this method are tuple(s) of the form (location, magnitude, direction).

        location: String or Symbol
            Label of the Node at which load is applied and is to be removed.

        magnitude: Sympifyable
            Magnitude of the load applied.

        direction: Sympifyable
            The angle, in degrees, that the load vector makes with the horizontal
            in the counter-clockwise direction. It takes the values 0 to 360,
            inclusive.

        Examples
        ========

        >>> from sympy.physics.continuum_mechanics.truss import Truss
        >>> from sympy import symbols
        >>> t = Truss()
        >>> t.add_node(('A', 0, 0), ('B', 3, 0))
        >>> P = symbols('P')
        >>> t.apply_load(('A', P, 90), ('A', P/2, 45), ('A', P/4, 90))
        >>> t.loads
        {'A': [[P, 90], [P/2, 45], [P/4, 90]]}
        >>> t.remove_load(('A', P/4, 90), ('A', P/2, 45))
        >>> t.loads
        {'A': [[P, 90]]}
        r   r7   r8   z&Load must be removed from a known nodezENo load of this magnitude and direction has been applied at this nodeN)r   r&   r9   r   rE   rF   r^   r)   r)   r*   remove_load  s   #
zTruss.remove_loadc                 G   s&  |D ]}|d }|d }|| j vrtd|| jvrT|dkr?| |tdt| d df | |tdt| d df nL|d	krS| |tdt| d df n7| j| dkrp|d	kro| |tdt| d df n| j| d	kr|dkr| |tdt| d df || j|< qd
S )a  
        This method adds a pinned or roller support at specified node(s).

        Parameters
        ==========
        The input(s) of this method are of the form (location, type).

        location: String or Symbol
            Label of the Node at which support is added.

        type: String
            Type of the support being provided at the node.

        Examples
        ========

        >>> from sympy.physics.continuum_mechanics.truss import Truss
        >>> t = Truss()
        >>> t.add_node(('A', 0, 0), ('B', 3, 0))
        >>> t.apply_support(('A', 'pinned'), ('B', 'roller'))
        >>> t.supports
        {'A': 'pinned', 'B': 'roller'}
        r   r7   z%Support must be added on a known noderO   rP   rQ   rR   rS   rT   N)r&   r9   r   rW   r   rV   rb   )r(   r<   r=   r_   typer)   r)   r*   apply_support;  s*   

 "   zTruss.apply_supportc                 G   s   |D ]Y}|| j vrtd|| jvrtd| j| dkr>| |tdt| d df | |tdt| d df n| j| d	krU| |tdt| d df | j| qd
S )aL  
        This method removes support from specified node(s.)

        Parameters
        ==========

        locations: String or Symbol
            Label of the Node(s) at which support is to be removed.

        Examples
        ========

        >>> from sympy.physics.continuum_mechanics.truss import Truss
        >>> t = Truss()
        >>> t.add_node(('A', 0, 0), ('B', 3, 0))
        >>> t.apply_support(('A', 'pinned'), ('B', 'roller'))
        >>> t.supports
        {'A': 'pinned', 'B': 'roller'}
        >>> t.remove_support('A','B')
        >>> t.supports
        {}
        z No such node exists in the Trussz+No support has been added to the given noderO   rP   rQ   r   rR   rS   rT   N)r&   r9   r   rb   r   rV   rF   )r(   r<   r_   r)   r)   r*   remove_supporth  s   

 " zTruss.remove_supportc              
      s>  d} j D ]$}|d  jv r) j|d  dkr|d7 }q j|d  dkr)|d7 }qdt j  t j| kr<td fddtdt j  D }tdt j d}d} j D ]a}|d  jv r j|d  D ]L}|d t	d	t
|d  d
 kr|d t	d	t
|d  d kr||  |d tt|d  d  8  < ||d   |d tt|d  d  8  < qk|d7 }q[d}d} j D ]N}|d  jv r j|d  dkr|| |  d7  < ||d  |d   d7  < |d7 }n j|d  dkr||d  |  d7  < |d7 }|d7 }qĈ jD ]}	 j|	 d }
 j|	 d }t j|
 d  j| d  d  j|
 d  j| d  d  } j|
} j|} j| d  j|
 d  | } j| d  j|
 d  | } j|
 d  j| d  | } j|
 d  j| d  | }||d  |  |7  < ||d d  |  |7  < ||d  |  |7  < ||d d  |  |7  < |d7 }qt|d | }i  _d}t} j D ])}|d  jv r j|d  D ]}t|d t	ttfvrt||d }qqtt|D ]}t|| t	ttfvr-t|| | dk r-d||< q j D ]X}|d  jv r j|d  dkrl||  jd	t
|d  d
 < ||d   jd	t
|d  d < |d7 }q2 j|d  dkr||  jd	t
|d  d < |d7 }q2 jD ]}	||  j|	< |d7 }qdS )a  
        This method solves for all reaction forces of all supports and all internal forces
        of all the members in the truss, provided the Truss is solvable.

        A Truss is solvable if the following condition is met,

        2n >= r + m

        Where n is the number of nodes, r is the number of reaction forces, where each pinned
        support has 2 reaction forces and each roller has 1, and m is the number of members.

        The given condition is derived from the fact that a system of equations is solvable
        only when the number of variables is lesser than or equal to the number of equations.
        Equilibrium Equations in x and y directions give two equations per node giving 2n number
        equations. However, the truss needs to be stable as well and may be unstable if 2n > r + m.
        The number of variables is simply the sum of the number of reaction forces and member
        forces.

        .. note::
           The sign convention for the internal forces present in a member revolves around whether each
           force is compressive or tensile. While forming equations for each node, internal force due
           to a member on the node is assumed to be away from the node i.e. each force is assumed to
           be compressive by default. Hence, a positive value for an internal force implies the
           presence of compressive force in the member and a negative value implies a tensile force.

        Examples
        ========

        >>> from sympy.physics.continuum_mechanics.truss import Truss
        >>> t = Truss()
        >>> t.add_node(("node_1", 0, 0), ("node_2", 6, 0), ("node_3", 2, 2), ("node_4", 2, 0))
        >>> t.add_member(("member_1", "node_1", "node_4"), ("member_2", "node_2", "node_4"), ("member_3", "node_1", "node_3"))
        >>> t.add_member(("member_4", "node_2", "node_3"), ("member_5", "node_3", "node_4"))
        >>> t.apply_load(("node_4", 10, 270))
        >>> t.apply_support(("node_1", "pinned"), ("node_2", "roller"))
        >>> t.solve()
        >>> t.reaction_loads
        {'R_node_1_x': 0, 'R_node_1_y': 20/3, 'R_node_2_y': 10/3}
        >>> t.internal_forces
        {'member_1': 20/3, 'member_2': 20/3, 'member_3': -20*sqrt(2)/3, 'member_4': -10*sqrt(5)/3, 'member_5': 10}
        r   rO   r8   rT   r7   z The given truss cannot be solvedc                    s(   g | ]}d d t dt j D qS )c                 S   s   g | ]}d qS )r   r)   ).0r=   r)   r)   r*   
<listcomp>  s    z*Truss.solve.<locals>.<listcomp>.<listcomp>r8   )rB   rC   r   )rf   jr'   r)   r*   rg     s   ( zTruss.solve.<locals>.<listcomp>rP   rQ   rR      g|=N)r   r   rC   r   r9   rB   r   r-   r   r   rV   r   r
   r   r   r&   r   rU   r	   r$   r   rc   r   r   minabsr%   )r(   count_reaction_loadsrY   coefficients_matrixload_matrixload_matrix_rowrZ   colsrowrH   rK   rL   lengthstart_index	end_indexhorizontal_component_startvertical_component_starthorizontal_component_endvertical_component_endforces_matrixr=   min_loadrh   r)   r'   r*   solve  s   *

 
@(,




D    

"
zTruss.solve)r   )modulesNc                 C   s  t stdtd}g }g }g }| |}||7 }|  }||7 }|  }||7 }|  }	||	7 }t }
t}t }t}| jD ]*}t	|
| j| d }
t
|| j| d }t	|| j| d }t
|| j| d }q>t	|
d |d  d |d |d  d }||
d |d  d krtd|ddf|d||d|  |
d f|d|  |
d fd|d		}|S td|ddf|d||d|  |d f|d|  |d fd|d		}|S )
ao  
        Returns a plot object of the Truss with all its nodes, members,
        supports and loads.

        .. note::
            The user must be careful while entering load values in their
            directions. The draw function assumes a sign convention that
            is used for plotting loads.

            Given a right-handed coordinate system with XYZ coordinates,
            the supports are assumed to be such that the reaction forces of a
            pinned support is in the +X and +Y direction while those of a
            roller support is in the +Y direction. For the load, the range
            of angles, one can input goes all the way to 360 degrees which, in the
            the plot is the angle that the load vector makes with the positive x-axis in the anticlockwise direction.

            For example, for a 90-degree angle, the load will be a vertically
            directed along +Y while a 270-degree angle denotes a vertical
            load as well but along -Y.

        Examples
        ========

        .. plot::
            :context: close-figs
            :format: doctest
            :include-source: True

            >>> from sympy.physics.continuum_mechanics.truss import Truss
            >>> import math
            >>> t = Truss()
            >>> t.add_node(("A", -4, 0), ("B", 0, 0), ("C", 4, 0), ("D", 8, 0))
            >>> t.add_node(("E", 6, 2/math.sqrt(3)))
            >>> t.add_node(("F", 2, 2*math.sqrt(3)))
            >>> t.add_node(("G", -2, 2/math.sqrt(3)))
            >>> t.add_member(("AB","A","B"), ("BC","B","C"), ("CD","C","D"))
            >>> t.add_member(("AG","A","G"), ("GB","G","B"), ("GF","G","F"))
            >>> t.add_member(("BF","B","F"), ("FC","F","C"), ("CE","C","E"))
            >>> t.add_member(("FE","F","E"), ("DE","D","E"))
            >>> t.apply_support(("A","pinned"), ("D","roller"))
            >>> t.apply_load(("G", 3, 90), ("E", 3, 90), ("F", 2, 90))
            >>> p = t.draw()
            >>> p  # doctest: +ELLIPSIS
            Plot object containing:
            [0]: cartesian line: 1 for x over (1.0, 1.0)
            ...
            >>> p.show()
        z-To use this function numpy module is requiredr?   r   r7   皙?皙?Fg?)markersshowannotationsxlimylimaxis
rectangles)r   ImportErrorr   _draw_nodes_draw_members_draw_supports_draw_loadsr   r&   maxrk   r   )r(   	subs_dictr?   r   r   r   node_markersmember_rectanglessupport_markersload_annotationsxmaxxminymaxyminrY   lim	sing_plotr)   r)   r*   draw  s:   2

*@@r   c                 C   s  g }| j D ]}t| j | d ttfv r0| j | d |v r,|| j | d  | j | d< nItdt| j | d tkru| j | d  }|D ].}t|ttfv rt|d ksX||vr\td| j | d  |  < | j | d  || 9  < qFt| j | d ttfv r| j | d |v r|| j | d  | j | d< qtdt| j | d tkr| j | d  }|D ].}t|ttfv r|d ks||vrtd| j | d  |  < | j | d  || 9  < qq| j D ]}|| j | d g| j | d ggdddd q|S )Nr   z/provided substituted dictionary is not adequater7   o   blackr<   marker
markersizecolor)r&   rc   r   r   r9   r   as_coeff_Mulr;   )r(   r   r   rY   objectsobjectr)   r)   r*   r   _  sJ   

zTruss._draw_nodesc                 C   s  g }t  }t }t  }t }| jD ]*}t|| j| d }t|| j| d }t|| j| d }t|| j| d }qtd| d|  td| d|  krWd| d|  }nd| d|  }| jD ]}| j| j| d  d }	| j| j| d  d }
| j| j| d  d }| j| j| d  d }||	kr^||
kr^||	kr||	d| ttd t	||
 ||	    d  |
d| t
td t	||
 ||	    d  ft|	| d |
| d  d| td  d| dt	||
 ||	   t d	d
 qb||d| ttd t	||
 ||	    d  |d| t
td t	||
 ||	    d  ft|	| d |
| d  d| td  d| dt	||
 ||	   t d	d
 qb||
kr||	kr||	d| d  |
d| d  ft|	| d |
| d  d| ddtd||	   d	d
 qb||	d| d  |
d| d  ft|	| d |
| d  d| ddtd||	   d	d
 qb|
|k r||	d| d  |
d| d  ft|	| d |
| d  d| d  d| dtd||
  d	d
 qb||d| d  |d| d  ft|	| d |
| d  d| d   d| dtd||
  d	d
 qb|S )Nr   r7   r~   r   g{Gzt?   r8   ri   brown)xywidthheightangler   rS   g{Gzt)r   r&   r   rk   rl   r   r;   r   r
   r   r   r   mathcopysign)r(   r   r   r   r   r   rY   max_diffrH   x1y1x2y2r)   r)   r*   r     s   
(
^,
^,
	



&
(
zTruss._draw_membersc              	   C   s  g }t  }t }t  }t }| jD ]*}t|| j| d }t|| j| d }t|| j| d }t|| j| d }qtd| d|  td| d|  krWd| d|  }nd| d|  }| jD ]}| j| dkr|| j| d g| j| d ggdddd	d
 || j| d g| j| d d|  ggdddd qb| j| dkr|| j| d g| j| d d|  ggdddd	d
 || j| d g| j| d d|  ggdddd qb|S )Nr   r7   r~   r   rO         r   none)r<   r   r   r   markerfacecolorgQ?_   r   rT   g{Gz?r      g333333?)r   r&   r   rk   rl   r   r;   )r(   r   r   r   r   r   rY   r   r)   r)   r*   r     sp   
(
zTruss._draw_supportsc                 C   s
  g }t  }t }t  }t }| jD ]*}t|| j| d }t|| j| d }t|| j| d }t|| j| d }qtd| d|  td| d|  krYd| d|  d }n
d| d|  d }| jD ]}| j| D ]}|d tdt| d tdt| d fv rqm| j| d }	| j| d }
|d	|	t	
t|d  d
 |d   |
t	t|d  d
 |d   f|	|d t||  t||  t	
t|d  d
  d  |
|d t||  t||  t	t|d  d
  d  fdddddd qmqf|S )Nr   r7   r~   r   r   rP   rQ   rR    ri   d      g      ?r   )r   
headlength	headwidth	facecolor)textr   xytext
arrowprops)r   r&   r   rk   rl   r   r   rV   r;   r   r   r
   r   )r(   r   r   r   r   r   rY   r   rZ   r?   r@   r)   r)   r*   r   -  s@   
(
0  <<zTruss._draw_loads)N) __name__
__module____qualname____doc__r+   propertyr-   r/   r0   r1   r2   r3   r4   r5   r6   rA   rI   rM   rN   r[   r]   rW   rb   rd   re   r|   r   r   r   r   r   r   r)   r)   r)   r*   r      sL    








530!_105-'s\-[Fr   )#r   cmathr   r   sympy.core.addr   sympy.core.evalfr   sympy.core.mulr   sympy.core.symbolr   sympy.core.sympifyr   sympyr	   r
   sympy.external.importtoolsr   (sympy.functions.elementary.miscellaneousr   sympy.matrices.denser   r   sympy.physics.units.quantitiesr   sympy.plottingr   sympy.utilities.decoratorr   r   r   __doctest_requires__r   r   r)   r)   r)   r*   <module>   s&    
