File indexing completed on 2022-11-29 18:41:51

0001 /*
0002     SPDX-FileCopyrightText: 1998-2001 Andreas Zehender <az@azweb.de>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #include "mathroutines.h"
0008 
0009 #include "math.h"
0010 
0011 double rectToAngle(double x,double y)
0012 {
0013    double phi=0;
0014    if(fabs(x)<1e-6)
0015    {
0016       if(y>0)
0017          phi=M_PI_2;
0018       else
0019          phi=-M_PI_2;
0020    }
0021    else
0022    {
0023       phi=atan(y/x);
0024       if(x<0)
0025          phi+=M_PI;
0026    }
0027    if(phi>M_PI)
0028       phi-=2*M_PI;
0029    return phi;
0030 }
0031 
0032 double average(double phi1,double phi2)
0033 {
0034    return phi2+difference(phi1,phi2)/2.0;
0035 }
0036 
0037 double difference(double phi1,double phi2)
0038 {
0039    double dif;
0040 
0041    dif=phi1-phi2;
0042    while(dif>M_PI)
0043       dif-=2*M_PI;
0044    while(dif<-M_PI)
0045       dif+=2*M_PI;
0046 
0047    return dif;
0048 }