File: pt2d.C

package info (click to toggle)
battleball 2.0-13
  • links: PTS
  • area: main
  • in suites: woody
  • size: 1,016 kB
  • ctags: 3,097
  • sloc: cpp: 15,310; makefile: 48; csh: 34
file content (67 lines) | stat: -rw-r--r-- 2,104 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// Copyright (c) 1997 Philip A. Hardin (pahardin@cs.utexas.edu)
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License v2 or later.


// pt2d class

#include "pt2d.h"



/*======================================================================*/
// Return value is in the range [-MA_PI/4, 7*MA_PI/4)
ang2d pt2d::Ang2d() const {
  if (x==0 and y==0) return 0;
  if (x  >=ABS(y)) return (ang2d)(      0   + (y * (MA_PI/4)) / x);
  if (-x >=ABS(y)) return (ang2d)(  MA_PI   + (y * (MA_PI/4)) / x);
  if (y  > ABS(x)) return (ang2d)(  MA_PI/2 - (x * (MA_PI/4)) / y);
                   return (ang2d)(3*MA_PI/2 - (x * (MA_PI/4)) / y);
}


/*----------------------------------------------------------------------*/
void pt2d::Interpolate(const pt2d& pt1, const pt2d& pt2, int i, int range)
{ if (range==0) return;
  x= pt1.x + i*(pt2.x -pt1.x)/range;
  y= pt1.y + i*(pt2.y -pt1.y)/range;
}


/*-------------------------------------------------------------------------*/
pt2d pt2d::Normalized(coord len) const
// Treating this pt as a vector, normalize so that vector length= len
{ return (*this) * (len/Dist());
}


/*----------------------------------------------------------------------*/
// Treating this pt as a vector, normalize so that vector length= len
void pt2d::Normalize(coord len)
{ *this *= len/Dist();
}


/*----------------------------------------------------------------------*/
// Treating this pt as a vector, normalize so that vector length= len
void pt2d::FastNormalize(coord len)
{ *this *= len/FastDist();
}


/*----------------------------------------------------------------------*/
pt2d pt2d::operator>>(double ang) const
{ double sinAng= sin(ang);
  double cosAng= cos(ang);
  return pt2d((coord)(cosAng*x - sinAng*y),(coord)(cosAng*y + sinAng*x));
}


/*----------------------------------------------------------------------*/
void pt2d::operator>>=(double ang)
{ double sinAng= sin(ang);
  double cosAng= cos(ang);
  coord	tempx= (coord)(cosAng*x - sinAng*y);
  y= (coord)(cosAng*y + sinAng*x);
  x= tempx;
}