⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 vector.cpp

📁 adaboost code in matlab
💻 CPP
字号:
#include "vector.h"
#include <math.h>
#include <stdlib.h>
#include <iostream.h>

// set x, y and z values of the current vector //
void Vector::set(double _x, double _y, double _z)
{
	x=_x;
	y=_y;
	z=_z;
}

// normalize the current vector to unit length //
void Vector::normalize(void)
{
	double d=sqrt(x*x+y*y+z*z);
	if(d == 0)
	{
		cout << "zero length vector\n";
		exit(1);
	}
	x /= d;
	y /= d;
	z /= d;
}

// scale the current vector with a constant //
Vector& Vector::scale(double coeff)
{
	x *= coeff;
	y *= coeff;
	z *= coeff;

	return  *this;
}

// calculate the dot product of the current vector with vector v //
double Vector::dotProd(const Vector& v)
{
	return x*v.x+y*v.y+z*v.z;
}

// calculate the cross product of the current vector with
// vector v, the resulting vector is stored in "res" //
void Vector :: crossProd(Vector& res, const Vector& v)
{
	double i=y*v.z-z*v.y;
	double j=z*v.x-x*v.z;
	double k=x*v.y-y*v.x;
	res.set(i, j, k);
}

// add the current vetor to vector v //
Vector Vector::operator+ (const Vector& v)
{
	Vector vec;
	double i=x+v.x;
	double j=y+v.y;
	double k=z+v.z;
	vec.set(i, j, k);

	return vec;
}

// subtract vector v from the current vector //
Vector Vector::operator- (const Vector& v)
{
	Vector vec;
	double i=x-v.x;
	double j=y-v.y;
	double k=z-v.z;
	vec.set(i, j, k);

	return vec;
}

Vector& Vector::operator= (const Vector& v)
{
	if(this==&v)
		return *this;
    x=v.x;
	y=v.y;
	z=v.z;

	return *this;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -