removed unused files from ccm example

This commit is contained in:
Mark Olesen
2008-05-08 13:37:30 +02:00
parent aad21d4575
commit 2744374ad0
2 changed files with 0 additions and 194 deletions

View File

@ -1,36 +0,0 @@
#include "Vector.h"
using namespace std;
float Vector::distanceToSegment(const Vector& p1, const Vector& p2) const
{
// vector from p1 to p2
Vector p1p2(p1,p2);
float length = p1p2.mag();
if (length <= 1.0e-9)
return Vector::distance(*this, p1);
p1p2.normalize();
// vector from p1 to this
Vector p1point(p1, *this);
// u is distance along segment from point 1
float u = Vector::dot(p1point, p1p2);
if (u <= 0.0) // closest to point 1
return p1point.mag();
else if (u >= length) // closest to point 2
return Vector::distance(*this, p2);
else // use pythagorean theorem to compute projected distance
return sqrt(p1point.mag_squared() - u*u);
return 0.0;
}
ostream& operator<< (ostream& s, const Vector& v)
{
s << "(" << v.x() << ", " << v.y() << ", " << v.z() << ")";
return s;
}

View File

@ -1,158 +0,0 @@
#ifndef _CCMVECTOR_H
#define _CCMVECTOR_H
#include <math.h>
#include <iostream>
class Vector
{
public:
Vector() {
_xyz[0] = 0.0;
_xyz[1] = 0.0;
_xyz[2] = 0.0;
}
Vector(float x, float y, float z) {
_xyz[0] = x;
_xyz[1] = y;
_xyz[2] = z;
}
Vector(const Vector& p1, const Vector& p2) {
_xyz[0] = p2._xyz[0] - p1._xyz[0];
_xyz[1] = p2._xyz[1] - p1._xyz[1];
_xyz[2] = p2._xyz[2] - p1._xyz[2];
}
Vector(const float *xyz) {
_xyz[0] = xyz[0];
_xyz[1] = xyz[1];
_xyz[2] = xyz[2];
}
void set(int i, float val) {
_xyz[i] = val;
}
void setXYZ(const float *xyz) {
_xyz[0] = xyz[0];
_xyz[1] = xyz[1];
_xyz[2] = xyz[2];
}
void setXYZ(float x, float y, float z) {
_xyz[0] = x;
_xyz[1] = y;
_xyz[2] = z;
}
void axpy(float a, const Vector& x, const Vector& y) {
_xyz[0] = a*x._xyz[0] + y._xyz[0];
_xyz[1] = a*x._xyz[1] + y._xyz[1];
_xyz[2] = a*x._xyz[2] + y._xyz[2];
}
float x() const {return _xyz[0];}
float y() const {return _xyz[1];}
float z() const {return _xyz[2];}
const float *xyz() const {return _xyz;}
float& operator[](unsigned int i) { return _xyz[i]; }
float mag() const {
return sqrt(_xyz[0]*_xyz[0] +
_xyz[1]*_xyz[1] +
_xyz[2]*_xyz[2]);
}
float mag_squared() const {
return _xyz[0]*_xyz[0] +
_xyz[1]*_xyz[1] +
_xyz[2]*_xyz[2];
}
int normalize() {
float mag = this->mag();
if (mag < 1.0e-9)
return 1;
float scale = 1.0f / mag;
for(int i=0; i<3; i++)
_xyz[i] *= scale;
return 0;
}
Vector& operator+=(const Vector& v1) {
_xyz[0] += v1._xyz[0];
_xyz[1] += v1._xyz[1];
_xyz[2] += v1._xyz[2];
return *this;
}
Vector& operator-=(const Vector& v1) {
_xyz[0] -= v1._xyz[0];
_xyz[1] -= v1._xyz[1];
_xyz[2] -= v1._xyz[2];
return *this;
}
Vector& operator*=(const float scale) {
_xyz[0] *= scale;
_xyz[1] *= scale;
_xyz[2] *= scale;
return *this;
}
Vector operator-(const Vector &v) const {
return Vector(
this->_xyz[0] - v._xyz[0],
this->_xyz[1] - v._xyz[1],
this->_xyz[2] - v._xyz[2]);
}
Vector operator+(const Vector &v) const {
return Vector(
this->_xyz[0] + v._xyz[0],
this->_xyz[1] + v._xyz[1],
this->_xyz[2] + v._xyz[2]);
}
static float distance(const Vector& v1, const Vector& v2) {
return sqrt((v1._xyz[0]-v2._xyz[0])*(v1._xyz[0]-v2._xyz[0])+
(v1._xyz[1]-v2._xyz[1])*(v1._xyz[1]-v2._xyz[1])+
(v1._xyz[2]-v2._xyz[2])*(v1._xyz[2]-v2._xyz[2]));
}
static float distance_squared(const Vector& v1, const Vector& v2) {
return (v1._xyz[0]-v2._xyz[0])*(v1._xyz[0]-v2._xyz[0])+
(v1._xyz[1]-v2._xyz[1])*(v1._xyz[1]-v2._xyz[1])+
(v1._xyz[2]-v2._xyz[2])*(v1._xyz[2]-v2._xyz[2]);
}
static Vector cross(const Vector& v1, const Vector& v2) {
return Vector(
v1._xyz[1] * v2._xyz[2] - v1._xyz[2] * v2._xyz[1],
v1._xyz[2] * v2._xyz[0] - v1._xyz[0] * v2._xyz[2],
v1._xyz[0] * v2._xyz[1] - v1._xyz[1] * v2._xyz[0]);
}
static Vector subtract_component(const Vector& v, const Vector& dir) {
float dot = Vector::dot(v, dir);
return Vector(v._xyz[0] - dot*dir._xyz[0],
v._xyz[1] - dot*dir._xyz[1],
v._xyz[2] - dot*dir._xyz[2]);
}
static float dot(const Vector& v1, const Vector& v2) {
return v1._xyz[0]*v2._xyz[0] +
v1._xyz[1]*v2._xyz[1] +
v1._xyz[2]*v2._xyz[2];
}
float distanceToSegment(const Vector& p1, const Vector& p2) const;
private:
float _xyz[3];
};
std::ostream& operator<< (std::ostream& s, const Vector& v);
#endif