CoolFace
Apppublic

Priante/boids_algorithm_app

sourceHugging Faceupdated 4y agoView on Hugging Face
0likes
functions.cpython-37.pyc39 linesDownload Raw Back to __pycache__
1B

2�(�cU�@sPdZddlZddlmZmZddlZdd�Zdd�Zdd	�Z	d3d�Z4dd
�ZdS)z95Created on Sat Aug 27 17:53:41 20226 7@author: francesca8�N)�pdist�9squareformcCs�ttt�||g���}||k}t�|�}t�|�}t�|�}	t�|�}10xztd|d�D]h}t�|||f�||<t�|||f�||<||||||	|<||||||11|<qVW|	|12fS)Nr�)rr�np�	transpose�zeros�range�mean)�x0�y0�neighbors_dist�n�R�m�idxZcenter_xZcenter_y�vx�vy�i�r�E/Users/francesca/Desktop/coding_shit/boids_algorithm_app/functions.py�moveToCenters13141516	rc17Cs�ttt�||g���}||k|dk@}t�t�t�|���}t�|�}t�|�}	||dd�df||dd�df|||dd�df<||dd�df||dd�df||	|dd�df<||	fS)Nrr)rrrr�array�wherer)18r19rr
�privacy�bird_repulsion�distZidxmatrrrrrr�avoidOthers+s2021<<rcCs�ttt�||g���}||k}t�|�}	t�|�}22xbtd|d�D]P}t�|||f|||f�|	|<t�|||f|||f�|23|<qBW|	||24|fS)Nrr)rrrrrrr	)�x_prev�y_prevr25rr
r�match_velocityrrZvmean_xZvmean_yrrrr�matchVelocities@s2627&*r cCs�t|||||�\}}t|||||�\}}t|||||||	�\}}|||||}|||||}t�d|f�}t�||g�}tjj|dd�}|dd�|dkf||dk|
|dd�|dkf<|ddd�f}|ddd�f}|28|}||29}|30|}||31}|||k||||k<|||k||||k<|||k||||k<|||k||||k<||}||}t�|�}t�|�}||fS)N�r)�axisr)	rrr rrr�linalg�norm�round)r32rrrr
rrrrr�L�margin�wall_repulsion�	max_speedZvx1Zvy1Zvx2Zvy2Zvx3Zvy3rrZv_normZv_vectorr$Zright_border_distZleft_border_distZupper_border_distZbottom_border_dist�x1�y1rrr�moveVs043334r,cCs<||g}tjt�|�|dd�tjj|dd�}t�|�}||dk||dk<|dk|tjk@}	t�|	�d}	d|	|	dk<|}35|	tjd||}t�	|�}|||k|||k<|||k|||k|36||k|||k<t�37|�tjj|dd�}
t�|�tjj|dd�}t�|
|d�}t�||d�}||fS)Nr)r"r�����r!�)
r�sumrr#r$�arccos�math�pi�asarrayr�cos�sinr%)Zvv_xZvv_yZ
perpendicular�dr'r
�vvZscalar_prodZalpha0Zincrease_angleZ	intercept�slope�	new_angleZnew_vvxZnew_vvyZdev_vvxZdev_vvyrrr�deviate_from_walls�s"(3839,r:)�__doc__�numpyrZscipy.spatial.distancerrr1rrr r,r:rrrr�<module>sE