Changeset 272 in Sophya for trunk/SophyaLib


Ignore:
Timestamp:
Apr 27, 1999, 5:12:57 PM (26 years ago)
Author:
ansari
Message:

Remplacement utilgeom.cc (confondu avec .h) Reza 27/04/99

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/SophyaLib/Samba/utilgeom.cc

    r262 r272  
    1 #ifndef MYFUNC_H_SEEN
    2 #define MYFUNC_H_SEEN
    31#include <math.h>
    4 #include <vector>
     2#include <iostream.h>
     3#include "utilgeom.h"
    54
    6 const double pi2=2.*M_PI;
    7 const double dtor=M_PI/180.;
    8 const double pi_over_2=M_PI/2.;
     5int sign(double d)
     6{
     7  return (d >= 0) - (d < 0);
     8}
    99
    10 int sign(double);
    11 double absd(double);
    12 double mod(double, double=0);
    13 void swap(double&, double&);
    14 double min(double, double);
    15 double max(double, double);
    16 int arrondi(double);
    17 double scangle(double sinus, double cosinus);
     10double absd(double d)
     11{
     12  return sqrt(d*d);
     13}
    1814
    19 #endif
     15double mod(double d, double periode)
     16{
     17  if( d >= 0 ) return d-floor(d/periode)*periode;
     18  else return d-ceil(d/periode)*periode+periode;
     19}
     20
     21void swap(double& d1, double& d2)
     22{
     23  double temp;
     24  temp=d2;
     25  d2=d1;
     26  d1=temp;
     27}
     28
     29double min(double d1, double d2)
     30{
     31  if( d1 >= d2 ) return d2;
     32  else return d1;
     33}
     34
     35double max(double d1, double d2)
     36{
     37  return -min(-d1,-d2);
     38}
     39
     40int arrondi(double d)
     41{
     42  return (int)(((d-floor(d)) >= 0.5)*ceil(d)+((d-floor(d)) < 0.5)*floor(d));
     43}
     44
     45long rangijd(int nc, int i, int j, int d)
     46{
     47  if( i < j ) return 2*i*(2*nc-i-1)+4*(j-i-1)+d;
     48  if( i > j ) return 2*j*(2*nc-j-1)+4*(i-j-1)+d+2;
     49  if( i == j )
     50    {
     51      cout << "pas d'intersection entre le cercle " << i
     52           << " et le cercle " << j << "." << endl;
     53      return -1;
     54    }
     55  else return -1;
     56}
     57
     58long rangdiff(int nc, int i, int j, int d)
     59{
     60  if( i == j )
     61    {
     62      cout << "diff n'est pas defini entre le cercle " << i
     63           << " et le cercle " << j << "." << endl;
     64      return 0;
     65    }
     66  int indm=(int)min(i,j);
     67  int indM=(int)max(i,j);
     68  return indm*(2*nc-indm-1)+2*(indM-indm-1)+d;
     69}
     70
     71long rangik(int NtotEch, int i, int k)
     72{
     73  return NtotEch*i+k;
     74}
     75
     76long ranghk(int NtotEch, int h, int k)
     77{
     78  return NtotEch*h+k;
     79}
     80
     81double scangle(double sinus, double cosinus)
     82{
     83  double eps=1e-10;
     84  if( fabs(1.-sinus*sinus-cosinus*cosinus) > eps || fabs(cosinus)-1. > eps || fabs(sinus)-1. > eps )
     85    {
     86      cerr << "angle non valide." << endl;
     87      cerr << "sinus = " << sinus << " cosinus = " << cosinus << endl;
     88      exit(0);
     89    }
     90  if( fabs(1.-fabs(cosinus)) < eps ) cosinus=1.*copysign(1.,cosinus);
     91  if( fabs(1.-fabs(sinus)) < eps ) sinus=1.*copysign(1.,sinus);
     92  if( fabs(sinus) == 0. ) sinus=0.;
     93  if( fabs(cosinus) == 0. ) cosinus=0.;
     94  return acos(cosinus)*copysign(1,sinus);
     95}
     96
     97//Matrix vecTxMat(const Vector& v, const Matrix& M) {
     98 
Note: See TracChangeset for help on using the changeset viewer.