Example #1
0
/* Project the cursor's current location onto the plane specified by the normal
 * vector 'normal' and a perpendicular distance 'dist' from the origin.
 */
vector
mousebase::project1( vector normal, double dist)
{
	double ndc = normal.dot(cam) - dist;
	double ndr = normal.dot(get_ray());
	double t = -ndc / ndr;
	vector v = cam + get_ray()*t;
	return v;
}
Example #2
0
int unsigned shape::support(vector const& direction) const {
  int unsigned support(0);
  float maximum_dot_product(direction.dot(vertices_[0]));
  for(int unsigned i(1); i < vertices_.size(); ++i) {
    float const dot_product = direction.dot(vertices_[i]);
    if(dot_product > maximum_dot_product) {
      support = i;
      maximum_dot_product = dot_product;
    }
  }
  return support;
}
Example #3
0
bool shape::intersects(shape const& shape) const {
  vector direction(shape.centroid() - centroid());

  std::vector<vector> simplex;
  simplex.push_back(vertices_[support(direction)] - shape.vertices()[shape.support(-direction)]);
  direction = -direction;

  for(;;) {
    vector const a(vertices_[support(direction)] - shape.vertices()[shape.support(-direction)]);
    if(a.dot(direction) <= 0.0f)
      return false;
    simplex.push_back(a);
    vector const ao(-a);

    if(simplex.size() == 3) {
      vector const b(simplex[1]);
      vector const c(simplex[0]);
      vector const ab(b - a);
      vector const ac(c - a);

      vector const ab_triple(vector::triple_product_left(ac, ab, ab));
      if(ab_triple.dot(ao) >= 0.0f) {
        simplex.erase(simplex.begin());
        direction = ab_triple;
      } else {
        vector const ac_triple(vector::triple_product_left(ab, ac, ac));
        if(ac_triple.dot(ao) >= 0.0f) {
          simplex.erase(simplex.begin() + 1);
          direction = ac_triple;
        } else
          return true;
      }
    } else {
      vector const b(simplex[0]);
      vector const ab(b - a);
      direction = vector::triple_product_left(ab, ao, ab);
      if(!direction)
        direction = ab.left();
    }
  }
}
Example #4
0
std::tuple<vector, vector> get_closest_points(vector const& a1,
                                              vector const& a2,
                                              vector const& a,
                                              vector const& b1,
                                              vector const& b2,
                                              vector const& b) {
  vector const lambda(b - a);

  if(!lambda)
    return std::make_tuple(a1, a2);

  float const lambda2(-lambda.dot(a) / lambda.length_squared());
  float const lambda1(1.0f - lambda2);

  if(lambda1 < 0.0f)
    return std::make_tuple(b1, b2);

  if(lambda2 < 0.0f)
    return std::make_tuple(a1, a2);

  return std::make_tuple(a1 * lambda1 + b1 * lambda2, a2 * lambda1 + b2 * lambda2);
}
Example #5
0
inline double
dot( const vector& v1, const vector& v2)
{ return v1.dot( v2); }
Example #6
0
inline T dot( const vector<T,D>& left, const vector<T,D>& right ) {
	return left.dot(right).extract();
}
  double sigmoidKernel::apply(const vector<double>& a,
                              const vector<double>& b) const {
    double t=a.dot(b);

    return tanh(getParameters().kappa*t + getParameters().theta);
  }
Example #8
0
 static vector triple_product_right(vector const &a, vector const &b, vector const &c) {
   return b * a.dot(c) - c * a.dot(b);
 }
Example #9
0
 static vector triple_product_left(vector const &a, vector const &b, vector const &c) {
   return b * c.dot(a) - a * c.dot(b);
 }