File: Geometry.cc

package info (click to toggle)
casacore 3.8.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 51,912 kB
  • sloc: cpp: 471,569; fortran: 16,372; ansic: 7,416; yacc: 4,714; lex: 2,346; sh: 1,865; python: 629; perl: 531; sed: 499; csh: 201; makefile: 32
file content (84 lines) | stat: -rw-r--r-- 2,719 bytes parent folder | download | duplicates (2)
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
//# Copyright (C) 2010 by ESO (in the framework of the ALMA collaboration)
//# Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002
//# Associated Universities, Inc. Washington DC, USA.
//#
//# This library is free software; you can redistribute it and/or modify it
//# under the terms of the GNU Library General Public License as published by
//# the Free Software Foundation; either version 2 of the License, or (at your
//# option) any later version.
//#
//# This library is distributed in the hope that it will be useful, but WITHOUT
//# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
//# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
//# License for more details.
//#
//# You should have received a copy of the GNU Library General Public License
//# along with this library; if not, write to the Free Software Foundation,
//# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
//#
//# Correspondence concerning AIPS++ should be addressed as follows:
//#        Internet email: casa-feedback@nrao.edu.
//#        Postal address: AIPS++ Project Office
//#                        National Radio Astronomy Observatory
//#                        520 Edgemont Road
//#                        Charlottesville, VA 22903-2475 USA
//   

#include <casacore/scimath/Mathematics/Geometry.h>
#include <casacore/casa/Arrays/MatrixMath.h>

namespace casacore {

	std::pair<Double, Double> Geometry::rotate2D(
		Double x, Double y, const Quantity& theta
	) {
		Double thetaRad = theta.getValue("rad");
		Double c = cos(thetaRad);
		Double s = sin(thetaRad);
		return std::make_pair(x*c - y*s, x*s + y*c);
	}


	Bool Geometry::doLineSegmentsIntersect(
		Double a0x, Double a0y, Double a1x, Double a1y,
		Double b0x, Double b0y, Double b1x, Double b1y
	) {
		Vector<Double > line0point0(2);
		line0point0[0] = a0x;
		line0point0[1] = a0y;
		Vector<Double > line0point1(2);
		line0point1[0] = a1x;
		line0point1[1] = a1y;
		Vector<Double > line1point0(2);
		line1point0[0] = b0x;
		line1point0[1] = b0y;
		Vector<Double > line1point1(2);
		line1point1[0] = b1x;
		line1point1[1] = b1y;

		Vector<Double> p = line0point0;
		Vector<Double> r = line0point1 - line0point0;
		Vector<Double> q = line1point0;
		Vector<Double> s = line1point1 - line1point0;
		Double rCrossS = crossProduct2D(r, s);
		Vector<Double> diffQP = q-p;

		if (rCrossS == 0) {
			if (crossProduct2D(diffQP, r) == 0) {
				// lines are coincident
				return True;
			}
			else {
				// lines are parallel
				return False;
			}
		}
		Double t = crossProduct2D(diffQP, s)/rCrossS;
		Double u = crossProduct2D(diffQP, r)/rCrossS;
		return t >= 0 && t <= 1 && u >= 0 && u <= 1;
	}



} //# NAMESPACE CASACORE - END