~ubuntu-branches/ubuntu/saucy/python-demgengeo/saucy

« back to all changes in this revision

Viewing changes to geometry/Cylinder.cc

  • Committer: Package Import Robot
  • Author(s): Anton Gladky
  • Date: 2011-11-18 21:47:18 UTC
  • Revision ID: package-import@ubuntu.com-20111118214718-4ysqm3dhpqwdd7gd
Tags: upstream-0.99~bzr106
ImportĀ upstreamĀ versionĀ 0.99~bzr106

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/////////////////////////////////////////////////////////////
 
2
//                                                         //
 
3
// Copyright (c) 2007-2011 by The University of Queensland //
 
4
// Earth Systems Science Computational Centre (ESSCC)      //
 
5
// http://www.uq.edu.au/esscc                              //
 
6
//                                                         //
 
7
// Primary Business: Brisbane, Queensland, Australia       //
 
8
// Licensed under the Open Software License version 3.0    //
 
9
// http://www.opensource.org/licenses/osl-3.0.php          //
 
10
//                                                         //
 
11
/////////////////////////////////////////////////////////////
 
12
 
 
13
#include "Cylinder.h"
 
14
 
 
15
Cylinder::Cylinder()
 
16
{
 
17
}
 
18
 
 
19
Cylinder::Cylinder(const Vector3& c,const Vector3& axis,double r)
 
20
{
 
21
  m_c=c;
 
22
  m_axis=axis;
 
23
  m_r=r;
 
24
}
 
25
 
 
26
/*!
 
27
  Get distance between a point and a cylindical surface. 
 
28
  The function returns the _absolute_ distance, i.e. the result 
 
29
  is always positive.
 
30
 
 
31
  \param P the point
 
32
*/
 
33
double Cylinder::getDist(const Vector3& P) const
 
34
{
 
35
  Vector3 v1=P-m_c;
 
36
  double d=m_axis*v1;
 
37
  return fabs(m_r-(v1-d*m_axis).norm());
 
38
}
 
39
 
 
40
/*!
 
41
  Get distance between a point and a cylindical surface. 
 
42
  The function returns the directed distance assuming an 
 
43
  inward facing surface normal, i.e. the result is positive 
 
44
  if the point is inside the cylinder and negative if it is 
 
45
  outside.
 
46
 
 
47
  \param P the point
 
48
*/
 
49
double Cylinder::getDirDist(const Vector3& P) const
 
50
{
 
51
  Vector3 v1=P-m_c;
 
52
  double d=m_axis*v1;
 
53
  return m_r-(v1-d*m_axis).norm();
 
54
}