CUDA常用数学运算符及数据结构重定义

这个代码段包含CUDA(Compute Unified Device Architecture)的数学函数定义,如atan2f, sqrt, cos和pow,并定义了多个向量类,如vec1b, vec3b, vec3f和vec4f,提供了加减乘除、比较和向量操作等方法。这些类支持在设备(GPU)和主机(CPU)上进行运算。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

#pragma once
#include <math.h>
#include "cuda_runtime.h"


#define HOD __host__ __device__

inline HOD float dev_atan2f(float  y, float  x)
{
	return atan2(y, x);
}
inline HOD float dev_sqrt(float  x)
{
	return sqrt(x);
}
inline HOD float dev_cos(float  x)
{
	return cos(x);
}
inline HOD float dev_pow(float x, float y)
{
	return pow(x,y);
}

inline HOD float dev_acos(float x)
{
	return acos(x);
}



class vec1b
{
public:
	uchar x;
	HOD vec1b(void)
	{
		this->x = 0.0f;

	}

	HOD vec1b(const uchar& x)
	{
		this->x = x;

	}

	HOD uchar operator[](int i) const
	{
		return (&x)[i];
	}

	HOD uchar& operator[](int i)
	{
		return (&x)[i];
	}

	HOD vec1b& operator = (const vec1b &v)
	{
		x = v.x;


		return *this;
	}

	HOD vec1b operator + (const vec1b& v) const
	{
		return vec1b(x + v.x);
	}

	HOD vec1b& operator += (const vec1b& v)
	{
		x += v.x;
		return *this;
	}

	HOD vec1b operator - (const vec1b& v) const
	{
		return vec1b(x - v.x);
	}

	HOD vec1b& operator -= (const vec1b& v)
	{
		x -= v.x;
		return *this;
	}

	HOD vec1b operator * (float f) const
	{
		return vec1b(x * f);
	}

	HOD vec1b& operator *= (float f)
	{
		x *= f;


		return *this;
	}

	HOD vec1b operator / (float f) const
	{
		float inv = 1.f / f;
		return vec1b(x * inv);
	}

	HOD vec1b& operator /= (float f)
	{
		float inv = 1.f / f;
		x *= inv;
		return *this;
	}

	HOD vec1b operator-() const
	{
		return vec1b(-x);
	}

	HOD bool operator < (const vec1b& V) const
	{
		return V.x < x;
	}

	HOD bool operator > (const vec1b& V) const
	{
		return V.x > x;
	}

	HOD bool operator == (const vec1b& V) const
	{
		return V.x == x;
	}

};


class vec3b
{
public:
	uchar x, y, z;
	HOD vec3b(void)
	{
		this->x = 0.0f;
		this->y = 0.0f;
		this->z = 0.0f;
	}

	HOD vec3b(const uchar& x, const uchar& y, const uchar& z)
	{
		this->x = x;
		this->y = y;
		this->z = z;
	}

	HOD vec3b(const uchar& xyz)
	{
		this->x = xyz;
		this->y = xyz;
		this->z = xyz;
	}

	HOD uchar operator[](int i) const
	{
		return (&x)[i];
	}

	HOD uchar& operator[](int i)
	{
		return (&x)[i];
	}

	HOD vec3b& operator = (const vec3b &v)
	{
		x = v.x;
		y = v.y;
		z = v.z;

		return *this;
	}


	HOD vec3b operator + (const vec3b& v) const
	{
		return vec3b(x + v.x, y + v.y, z + v.z);
	}

	HOD vec3b& operator += (const vec3b& v)
	{
		x += v.x; y += v.y; z += v.z;
		return *this;
	}

	HOD vec3b operator - (const vec3b& v) const
	{
		return vec3b(x - v.x, y - v.y, z - v.z);
	}

	HOD vec3b& operator -= (const vec3b& v)
	{
		x -= v.x; y -= v.y; z -= v.z;
		return *this;
	}

	HOD vec3b operator * (float f) const
	{
		return vec3b(x * f, y * f, z * f);
	}

	HOD vec3b& operator *= (float f)
	{
		x *= f;
		y *= f;
		z *= f;

		return *this;
	}

	HOD vec3b operator / (float f) const
	{
		float inv = 1.f / f;
		return vec3b(x * inv, y * inv, z * inv);
	}

	HOD vec3b& operator /= (float f)
	{
		float inv = 1.f / f;
		x *= inv; y *= inv; z *= inv;
		return *this;
	}

	HOD vec3b operator-() const
	{
		return vec3b(-x, -y, -z);
	}

	HOD bool operator < (const vec3b& V) const
	{
		return V.x < x && V.y < y && V.z < z;
	}

	HOD bool operator > (const vec3b& V) const
	{
		return V.x > x && V.y > y && V.z > z;
	}

	HOD bool operator == (const vec3b& V) const
	{
		return V.x == x && V.y == y && V.z == z;
	}

};


class vec3f
{
public:
	HOD vec3f(void)
	{
		x = 0.0f;
		y = 0.0f;
		z = 0.0f;
	}

	HOD vec3f(const float& x, const float& y, const float& z)
	{
		this->x = x;
		this->y = y;
		this->z = z;
	}

	HOD vec3f(const float& xyz)
	{
		this->x = xyz;
		this->y = xyz;
		this->z = xyz;
	}

	HOD float operator[](int i) const
	{
		return (&x)[i];
	}

	HOD float& operator[](int i)
	{
		return (&x)[i];
	}

	HOD vec3f& operator = (const vec3f &v)
	{
		x = v.x;
		y = v.y;
		z = v.z;

		return *this;
	}

	HOD vec3f operator + (const vec3f& v) const
	{
		return vec3f(x + v.x, y + v.y, z + v.z);
	}

	HOD vec3f& operator += (const vec3f& v)
	{
		x += v.x; y += v.y; z += v.z;
		return *this;
	}

	HOD vec3f operator - (const vec3f& v) const
	{
		return vec3f(x - v.x, y - v.y, z - v.z);
	}

	HOD vec3f& operator -= (const vec3f& v)
	{
		x -= v.x; y -= v.y; z -= v.z;
		return *this;
	}

	HOD vec3f operator * (float f) const
	{
		return vec3f(x * f, y * f, z * f);
	}

	HOD vec3f& operator *= (float f)
	{
		x *= f;
		y *= f;
		z *= f;

		return *this;
	}

	HOD vec3f operator / (float f) const
	{
		float inv = 1.f / f;
		return vec3f(x * inv, y * inv, z * inv);
	}

	HOD vec3f& operator /= (float f)
	{
		float inv = 1.f / f;
		x *= inv; y *= inv; z *= inv;
		return *this;
	}


	HOD vec3f operator-() const
	{
		return vec3f(-x, -y, -z);
	}

	HOD bool operator < (const vec3f& V) const
	{
		return V.x < x && V.y < y && V.z < z;
	}

	HOD bool operator > (const vec3f& V) const
	{
		return V.x > x && V.y > y && V.z > z;
	}

	HOD bool operator == (const vec3f& V) const
	{
		return V.x == x && V.y == y && V.z == z;
	}

	HOD float Max(void) const
	{
		if (x >= y && x >= z)
		{
			return x;
		}
		else
		{
			if (y >= x && y >= z)
				return y;
			else
				return z;
		}
	}

	HOD float Min(void) const
	{
		if (x <= y && x <= z)
		{
			return x;
		}
		else
		{
			if (y <= x && y <= z)
				return y;
			else
				return z;
		}
	}

	HOD float LengthSquared(void) const
	{
		return x * x + y * y + z * z;
	}

	HOD float Length(void) const
	{
		return sqrtf(LengthSquared());
	}

	HOD void Normalize(void)
	{
		const float L = Length();
		x /= L;
		y /= L;
		z /= L;
	}

	HOD float Dot(const vec3f& rhs) const
	{
		return (x * rhs.x + y * rhs.y + z * rhs.z);
	}

	HOD vec3f Cross(const vec3f& rhs) const
	{
		return vec3f((y * rhs.z) - (z * rhs.y),
			(z * rhs.x) - (x * rhs.z),
			(x * rhs.y) - (y * rhs.x));
	}

	HOD void ScaleBy(const float& factor)
	{
		x *= factor;
		y *= factor;
		z *= factor;
	}

	float x, y, z;
};


class vec4f
{
public:
	HOD vec4f(void)
	{
		x = 0.0f;
		y = 0.0f;
		z = 0.0f;
		w = 0.0f;
	}

	HOD vec4f(const float& x, const float& y, const float& z, const float& w)
	{
		this->x = x;
		this->y = y;
		this->z = z;
		this->w = w;
	}

	HOD vec4f(const float& xyzw)
	{
		this->x = xyzw;
		this->y = xyzw;
		this->z = xyzw;
		this->w = xyzw;
	}

	HOD float operator[](int i) const
	{
		return (&x)[i];
	}

	HOD float& operator[](int i)
	{
		return (&x)[i];
	}

	HOD vec4f& operator = (const vec4f &v)
	{
		x = v.x;
		y = v.y;
		z = v.z;
		w = v.w;
		return *this;
	}

	HOD vec4f operator + (const vec4f& v) const
	{
		return vec4f(x + v.x, y + v.y, z + v.z, w + v.w);
	}

	HOD vec4f& operator += (const vec4f& v)
	{
		x += v.x; y += v.y; z += v.z; w += v.w;
		return *this;
	}

	HOD vec4f operator - (const vec4f& v) const
	{
		return vec4f(x - v.x, y - v.y, z - v.z, w - v.w);
	}

	HOD vec4f& operator -= (const vec4f& v)
	{
		x -= v.x; y -= v.y; z -= v.z; w -= v.w;
		return *this;
	}

	HOD vec4f operator * (float f) const
	{
		return vec4f(x * f, y * f, z * f, w*f);
	}

	HOD vec4f& operator *= (float f)
	{
		x *= f;
		y *= f;
		z *= f;
		w *= f;
		return *this;
	}

	HOD vec4f operator / (float f) const
	{
		float inv = 1.f / f;
		return vec4f(x * inv, y * inv, z * inv, w*inv);
	}

	HOD vec4f& operator /= (float f)
	{
		float inv = 1.f / f;
		x *= inv; y *= inv; z *= inv; w *= inv;
		return *this;
	}


	HOD vec4f operator-() const
	{
		return vec4f(-x, -y, -z, -w);
	}

	HOD bool operator < (const vec4f& V) const
	{
		return V.x < x && V.y < y && V.z < z;
	}

	HOD bool operator > (const vec4f& V) const
	{
		return V.x > x && V.y > y && V.z > z;
	}

	HOD bool operator == (const vec4f& V) const
	{
		return V.x == x && V.y == y && V.z == z;
	}

	HOD float Max(void) const
	{
		if (x >= y && x >= z)
		{
			return x;
		}
		else
		{
			if (y >= x && y >= z)
				return y;
			else
				return z;
		}
	}

	HOD float Min(void) const
	{
		if (x <= y && x <= z)
		{
			return x;
		}
		else
		{
			if (y <= x && y <= z)
				return y;
			else
				return z;
		}
	}

	HOD float LengthSquared(void) const
	{
		return x * x + y * y + z * z;
	}

	HOD float Length(void) const
	{
		return sqrtf(LengthSquared());
	}

	HOD void Normalize(void)
	{
		const float L = Length();
		x /= L;
		y /= L;
		z /= L;
	}

	HOD float Dot(const vec4f& rhs) const
	{
		return (x * rhs.x + y * rhs.y + z * rhs.z);
	}

	HOD vec4f Cross(const vec4f& rhs) const
	{
		return vec4f((y * rhs.z) - (z * rhs.y),
			(z * rhs.x) - (x * rhs.z),
			(x * rhs.y) - (y * rhs.x), (x * rhs.y) - (y * rhs.x));
	}

	HOD void ScaleBy(const float& factor)
	{
		x *= factor;
		y *= factor;
		z *= factor;
	}

	float x, y, z, w;
};


class vec4b
{
public:
	uchar x, y, z, w;
	HOD vec4b(void)
	{
		this->x = 0.0f;
		this->y = 0.0f;
		this->z = 0.0f;
		this->w = 0.0f;
	}

	HOD vec4b(const uchar& x, const uchar& y, const uchar& z, const uchar& w)
	{
		this->x = x;
		this->y = y;
		this->z = z;
		this->w = w;
	}

	HOD vec4b(const uchar& xyz)
	{
		this->x = xyz;
		this->y = xyz;
		this->z = xyz;
		this->w = xyz;
	}

	HOD uchar operator[](int i) const
	{
		return (&x)[i];
	}

	HOD uchar& operator[](int i)
	{
		return (&x)[i];
	}

	HOD vec4b& operator = (const vec4b &v)
	{
		x = v.x;
		y = v.y;
		z = v.z;
		w = v.w;
		return *this;
	}

	HOD vec4b operator + (const vec4b& v) const
	{
		return vec4b(x + v.x, y + v.y, z + v.z, w + v.w);
	}

	HOD vec4b& operator += (const vec4b& v)
	{
		x += v.x; y += v.y; z += v.z; w += v.w;
		return *this;
	}

	HOD vec4b operator - (const vec4b& v) const
	{
		return vec4b(x - v.x, y - v.y, z - v.z, w - v.w);
	}

	HOD vec4b& operator -= (const vec4b& v)
	{
		x -= v.x; y -= v.y; z -= v.z; w -= v.w;
		return *this;
	}

	HOD vec4b operator * (float f) const
	{
		return vec4b(x * f, y * f, z * f, w*f);
	}

	HOD vec4b& operator *= (float f)
	{
		x *= f;
		y *= f;
		z *= f;
		w *= f;
		return *this;
	}

	HOD vec4b operator / (float f) const
	{
		float inv = 1.f / f;
		return vec4b(x * inv, y * inv, z * inv, w*inv);
	}

	HOD vec4b operator-() const
	{
		return vec4b(-x, -y, -z, -w);
	}

	HOD bool operator < (const vec4b& V) const
	{
		return V.x < x && V.y < y && V.z < z&&V.w<w;
	}

	HOD bool operator > (const vec4b& V) const
	{
		return V.x > x && V.y > y && V.z > z&&V.w>w;
	}

	HOD bool operator == (const vec4b& V) const
	{
		return V.x == x && V.y == y && V.z == z && V.w == w;
	}

};

/*
template<typename T>
class HOD_vector
{
public:

HOD HOD_vector()
: first_(new T[2]), last_(first_), endl_(first_ + 2)
{
}

HOD ~HOD_vector()
{
delete[]first_;
first_ = endl_ = last_ = NULL;
}

HOD HOD_vector(const HOD_vector<T> &src)
{
{
int size = src.last_ - src.first_;
first_ = new T[src.endl_ - src.first_];
for (int i = 0; i < size; ++i)
{
first_[i] = src.first_[i];
}
last_ = first_ + size;
endl_ = first_ + (src.endl_ - src.first_);
}
}
HOD T& operator[](int i)
{
iterator _It ;
return _It[i];
}
HOD T& operator[](int i) const
{
iterator _It ;

return _It[i];
}
HOD HOD_vector<T>& operator=(const HOD_vector<T> &src)
{
if (this == &src)
{
return*this;
}
delete[]first_;
first_ = NULL;

int size = src.last_ - src.first_;
first_ = new T[src.endl_ - src.first_];
for (int i = 0; i < size; ++i)
{
first_[i] = src.first_[i];
}
last_ = first_ + size;
endl_ = first_ + (src.endl_ - src.first_);
return*this;
}


HOD bool full()
{
return first_ == endl_;
}
// 给容器末尾添加元素
HOD void push_back(const T &val)
{
if (full())
{
reSize();
}
*last_++ = val;
}
template<typename ...Args>
HOD void emplace_back(Args&&... args)
{
if (size() == capacity())
{
reallocate();
}
::new((void*)last_) T(std::forward<Args>(args)...);
++last_;
}
HOD void reallocate()
{
int maxlen = capacity() + capacity() / 2;
int len = size();
T* cur = new T[maxlen];
::memcpy(cur, first_, len * sizeof(T));
delete[] first_;
first_ = cur;
last_ = first_ + len;
endl_ = first_ + maxlen;
}


HOD int size() const { return last_ - first_; }
HOD int capacity() const { return endl_ - first_; }

// 从末尾删除元素
HOD void pop_back()
{
if (last_ == first_)
{
return;
}
--last_;
}

HOD int size()
{
return last_ - first_;
}
/*
HOD int size() const
{
return last_ - first_;
}

class iterator
{
public:
iterator(T*ptr = NULL) :_ptr(ptr) {}
//iterator(T*ptr = NULL, int pos = 0){ _ptr = _ptr + pos; }
bool operator!=(const iterator&it)
{
return _ptr != it._ptr;
}
bool operator++()
{
_ptr++;
return true;
}
T&operator*()
{
return *_ptr;
}
T operator[](int index)
{
return _ptr[index];
}
private:
mutable T*_ptr;
};
iterator begin() { return iterator(first_); }
iterator end() { return iterator(last_); }


private:
mutable T *first_; // 表数组的起始地址HOD_Point2f
mutable T *last_;  // 表示最后一个元素的后继位置的地址
mutable T *endl_;   // 末尾位置的后继位置
mutable T *w;
HOD void reSize()
{
int len = size();
T*tmp = new T[size() * 2];
int i = 0;
for (; i < len; ++i)
{
tmp[i] = first_[i];
}
delete[]first_;
first_ = tmp;
endl_ = first_ + len * 2;
last_ = first_ + len;
}

};
*/
class HOD_Point2f
{
public:
	HOD HOD_Point2f(float x = 0, float y = 0);
	HOD HOD_Point2f(const HOD_Point2f &);
	HOD bool operator==(const HOD_Point2f &) const;
	HOD bool operator!=(const HOD_Point2f &) const;
	HOD HOD_Point2f operator=(const HOD_Point2f &);
	HOD HOD_Point2f operator=(const cv::Point2f &);
	HOD HOD_Point2f operator+=(const HOD_Point2f &);
	HOD HOD_Point2f operator-=(const HOD_Point2f &);
	HOD HOD_Point2f operator+(const HOD_Point2f &) const;
	HOD HOD_Point2f operator-(const HOD_Point2f &) const;
	HOD HOD_Point2f operator*(const HOD_Point2f &) const;
	HOD HOD_Point2f operator/(int right) const {
		HOD_Point2f multi;
		multi.x = x / right;
		multi.y = y / right;
		return multi;
	}
	HOD float dot(const HOD_Point2f &) const;
	float x;
	float y;
};

HOD inline HOD_Point2f::HOD_Point2f(float a, float b)
{
	x = a;
	y = b;
}
HOD inline HOD_Point2f::HOD_Point2f(const HOD_Point2f &a)
{
	x = a.x;
	y = a.y;
}
HOD inline bool HOD_Point2f::operator==(const HOD_Point2f &right)const
{
	if (x == right.x && y == right.y)
		return true;
	else return false;
}
HOD inline bool HOD_Point2f::operator!=(const HOD_Point2f &right) const
{
	if (x == right.x && y == right.y)
		return false;
	else return true;
}
HOD inline HOD_Point2f HOD_Point2f::operator+=(const HOD_Point2f &right)
{
	x += right.x;
	y += right.y;
	return *this;
}
HOD inline HOD_Point2f HOD_Point2f::operator-=(const HOD_Point2f &right)
{
	x -= right.x;
	y -= right.y;
	return *this;
}
HOD inline HOD_Point2f HOD_Point2f::operator=(const HOD_Point2f &right)
{
	x = right.x;
	y = right.y;
	return *this;
}
HOD inline HOD_Point2f HOD_Point2f::operator=(const cv::Point2f &right)
{
	x = right.x;
	y = right.y;
	return *this;
}

HOD inline HOD_Point2f HOD_Point2f::operator+(const HOD_Point2f &right)const
{
	HOD_Point2f plus;
	plus.x = x + right.x;
	plus.y = y + right.y;
	return plus;
}
HOD inline HOD_Point2f HOD_Point2f::operator-(const HOD_Point2f &right)const
{
	HOD_Point2f minus;
	minus.x = x - right.x;
	minus.y = y - right.y;
	return minus;
}
HOD inline HOD_Point2f HOD_Point2f::operator*(const HOD_Point2f &right)const
{
	HOD_Point2f multi;
	multi.x = x * right.x;
	multi.y = y * right.y;
	return multi;
}
HOD inline float HOD_Point2f::dot(const HOD_Point2f &right) const
{
	HOD_Point2f multi;

	return (multi.x*right.x + multi.y*right.y);
}

HOD inline float Norm(const HOD_Point2f &right)
{

	return std::sqrt(right.x*right.x + right.y*right.y);
}




class HOD_Point2i
{
public:
	HOD HOD_Point2i(int x = 0, int y = 0);
	HOD HOD_Point2i(const HOD_Point2i &);
	HOD bool operator==(const HOD_Point2i &) const;
	HOD bool operator!=(const HOD_Point2i &) const;
	HOD HOD_Point2i operator=(const HOD_Point2i &);
	HOD HOD_Point2i operator=(const cv::Point2i &);
	HOD HOD_Point2i operator+=(const HOD_Point2i &);
	HOD HOD_Point2i operator-=(const HOD_Point2i &);
	HOD HOD_Point2i operator+(const HOD_Point2i &) const;
	HOD HOD_Point2i operator-(const HOD_Point2i &) const;
	HOD HOD_Point2i operator*(const HOD_Point2i &) const;
	HOD HOD_Point2i operator/(int right) const {
		HOD_Point2i multi;
		multi.x = x / right;
		multi.y = y / right;
		return multi;
	}
	HOD int dot(const HOD_Point2i &) const;
	int x;
	int y;
};

HOD inline HOD_Point2i::HOD_Point2i(int a, int b)
{
	x = a;
	y = b;
}
HOD inline HOD_Point2i::HOD_Point2i(const HOD_Point2i &a)
{
	x = a.x;
	y = a.y;
}
HOD inline bool HOD_Point2i::operator==(const HOD_Point2i &right)const
{
	if (x == right.x && y == right.y)
		return true;
	else return false;
}
HOD inline bool HOD_Point2i::operator!=(const HOD_Point2i &right) const
{
	if (x == right.x && y == right.y)
		return false;
	else return true;
}
HOD inline HOD_Point2i HOD_Point2i::operator+=(const HOD_Point2i &right)
{
	x += right.x;
	y += right.y;
	return *this;
}
HOD inline HOD_Point2i HOD_Point2i::operator-=(const HOD_Point2i &right)
{
	x -= right.x;
	y -= right.y;
	return *this;
}
HOD inline HOD_Point2i HOD_Point2i::operator=(const HOD_Point2i &right)
{
	x = right.x;
	y = right.y;
	return *this;
}
HOD inline HOD_Point2i HOD_Point2i::operator=(const cv::Point2i &right)
{
	x = right.x;
	y = right.y;
	return *this;
}

HOD inline HOD_Point2i HOD_Point2i::operator+(const HOD_Point2i &right)const
{
	HOD_Point2i plus;
	plus.x = x + right.x;
	plus.y = y + right.y;
	return plus;
}
HOD inline HOD_Point2i HOD_Point2i::operator-(const HOD_Point2i &right)const
{
	HOD_Point2i minus;
	minus.x = x - right.x;
	minus.y = y - right.y;
	return minus;
}
HOD inline HOD_Point2i HOD_Point2i::operator*(const HOD_Point2i &right)const
{
	HOD_Point2i multi;
	multi.x = x * right.x;
	multi.y = y * right.y;
	return multi;
}
HOD inline int HOD_Point2i::dot(const HOD_Point2i &right) const
{
	HOD_Point2f multi;

	return (multi.x*right.x + multi.y*right.y);
}

HOD inline int Norm(const HOD_Point2i &right)
{

	return std::sqrt(right.x*right.x + right.y*right.y);
}

HOD struct Point2Df
{
	float x, y;
};


//类定义:二维向量
class Vector2d
{
public:
	double x_;
	double y_;

public:
	HOD Vector2d(double x, double y) :x_(x), y_(y) {}
	HOD Vector2d() :x_(0), y_(0) {}

	//二维向量叉乘, 叉乘的结果其实是向量,方向垂直于两个向量组成的平面,这里我们只需要其大小和方向
	HOD double CrossProduct(const Vector2d vec)
	{
		return x_*vec.y_ - y_*vec.x_;
	}

	//二维向量点积
	HOD double DotProduct(const Vector2d vec)
	{
		return x_ * vec.x_ + y_ * vec.y_;
	}

	//二维向量减法
	HOD Vector2d Minus(const Vector2d vec) const
	{
		return Vector2d(x_ - vec.x_, y_ - vec.y_);
	}

	//判断点M,N是否在直线AB的同一侧
	HOD static bool IsPointAtSameSideOfLine(const Vector2d &pointM, const Vector2d &pointN,
		const Vector2d &pointA, const Vector2d &pointB)
	{
		Vector2d AB = pointB.Minus(pointA);
		Vector2d AM = pointM.Minus(pointA);
		Vector2d AN = pointN.Minus(pointA);

		//等于0时表示某个点在直线上
		return AB.CrossProduct(AM) * AB.CrossProduct(AN) >= 0;
	}
};


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

AplusX

踩坑不易,打个赏呗~

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值