File: Corner2D.cpp

package info (click to toggle)
esys-particle 2.1-4
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 7,284 kB
  • sloc: cpp: 77,304; python: 5,647; makefile: 1,176; sh: 10
file content (128 lines) | stat: -rw-r--r-- 2,879 bytes parent folder | download
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/////////////////////////////////////////////////////////////
//                                                         //
// Copyright (c) 2003-2011 by The University of Queensland //
// Earth Systems Science Computational Centre (ESSCC)      //
// http://www.uq.edu.au/esscc                              //
//                                                         //
// Primary Business: Brisbane, Queensland, Australia       //
// Licensed under the Open Software License version 3.0    //
// http://www.opensource.org/licenses/osl-3.0.php          //
//                                                         //
/////////////////////////////////////////////////////////////

#include "Corner2D.h"
#include "console.h"

/*!
  constructor, make sure Z=0;

  \param pos the position of the corner
  \param id the node id
*/
Corner2D::Corner2D(const Vec3& pos, int id)
{
  m_p=pos;
  m_p.Z()=0.0;
  m_id=id;
}


/*!
  add Edge to corner
  
  \param edge a pointer to the edge
*/ 
void Corner2D::addEdge(Edge2D* edge)
{
  m_edges.push_back(edge);
}

/*!
  get distance between corner and point

  \param p the point
*/
double Corner2D::sep(const Vec3& p) const
{
  return (m_p-p).norm();
}


/*!
  check if the contact between a particle at a point and the 
  corner is valid or if there is a contact between the particle
  and any of the adjacent edges or triangles

  \param p the center of the particle 
*/
bool Corner2D::isValidContact(const Vec3& p) const
{
  bool res=true;

  // check vs. Edges
  vector<Edge2D*>::const_iterator eiter=m_edges.begin();
  while((eiter!=m_edges.end())&&(res)){
    res=!((*eiter)->dist(p).first);
    eiter++;
  }

  return res;
}

/*!
  get the unit direction vector between a point and the corner

  \param p the point
*/
Vec3 Corner2D::getDirectionFromPoint(const Vec3& p) const
{
  return (p-m_p).unit();
}

/*!
  move the corner, make sure Z=0;

  \param d the displacement
*/
void Corner2D::move(const Vec3& d)
{
  m_p+=d;
  m_p.Z()=0.0;
}

/*!
  get normal of an edge

  \param idx which egde (1,2) to get
*/
Vec3 Corner2D::getEdgeNormal(int idx) const
{
  Vec3 res;

  if((idx==1) && (m_edges.size()>=1)) {
    res=(m_edges[0])->getNormal();
  } else if ((idx==2) && (m_edges.size()>=2)) {
    res=(m_edges[1])->getNormal();
  } else {
    console.Error() << "Error in Corner2D::getEdgeNormal: idx=" << idx << " nr. of edges: " << m_edges.size() << "\n";
  }

  return res;
}

/*!
  apply force to one of the attached edges

  \param idx which egde (1,2)
  \param F the force
*/
void Corner2D::applyForceToEdge(int idx,const Vec3& f)
{
  if((idx==1) && (m_edges.size()>=1)) {
    (m_edges[0])->applyForce(f);
  } else if ((idx==2) && (m_edges.size()>=2)) {
    (m_edges[1])->applyForce(f);
  } else {
    console.Error() << "Error in Corner2D::applyForceToEdge : idx=" << idx << " nr. of edges: " << m_edges.size() << "\n";
  }
}