文章目录
在开发平面几何方面的软件时,经常遇到的问题是点,角和线的运算,作者根据自己平时遇到的问题,梳理了几个常用的函数,供需要的读者使用,使用C++开发,分为头文件和实现文件,APlaneGeometryCompute.h和APlaneGeometryCompute.cpp.
1.APlaneGeometryCompute.h
- 1.APlaneGeometryCompute.h
- 2.APlaneGeometryCompute.cpp
- 3.读者答疑
#pragma once
class APlaneGeometryCompute
{
public:
APlaneGeometryCompute(void);
~APlaneGeometryCompute(void);
};
class AJZPoint2D{
public:
AJZPoint2D(double _x,double _y){
x=_x;
y=_y;
}
~AJZPoint2D(){
}
AJZPoint2D(){
x=0;
y=0;
}
//单位向量
AJZPoint2D UnitVector();
//两点相加
AJZPoint2D operator+(AJZPoint2D pt){
AJZPoint2D rltPt;
rltPt.x=this->x+pt.x;
rltPt.y=this->y+pt.y;
return rltPt;
}
AJZPoint2D operator-(AJZPoint2D pt){
AJZPoint2D rltPt;
rltPt.x=this->x-pt.x;
rltPt.y=this->y-pt.y;
return rltPt;
}
AJZPoint2D operator*(double s){
AJZPoint2D rltPt;
rltPt.x=this->x*s;
rltPt.y=this->y*s;
return rltPt;
}
AJZPoint2D operator/(double s){
AJZPoint2D rltPt;
rltPt.x=this->x/s;
rltPt.y=this->y/s;
return rltPt;
}
//绕原点的逆时针方向角
double ClockAngleByOrg();
public:
double x;
double y;
};
//角度转弧度
double Degree2Radius(double d);
//弧度转角度
double Radius2Degree(double r);
//求点到线段的垂足
AJZPoint2D GetFootPoint(AJZPoint2D point, AJZPoint2D pnt1, AJZPoint2D pnt2);
//求点到线段的距离
double GetDistancePoineToLine_planeCoord(AJZPoint2D point, AJZPoint2D pnt1, AJZPoint2D pnt2);
//求3点确定的前两点表示矩形的另外两个点,并返回前两点朝另外两点的法向量
AJZPoint2D GetRectOtherTwoPoints(
AJZPoint2D linePt1,AJZPoint2D linePt2,AJZPoint2D directPt3,AJZPoint2D& rectPt4,AJZPoint2D& rectPt5);
//点沿单位向量前进距离dis
AJZPoint2D PointExtendDis(AJZPoint2D pt,AJZPoint2D vec,double dis);
//一点绕另外一点逆时针旋转
AJZPoint2D RotatePoint(AJZPoint2D centerPt,AJZPoint2D srcPt,double angle_degree);
//求线段的垂直向上单位向量
AJZPoint2D LineVectorVecTop(AJZPoint2D linept1,AJZPoint2D linept2);
2.APlaneGeometryCompute.cpp
#include "IllustratorSDK.h"
#include "APlaneGeometryCompute.h"
#include "Math.h"
#define _PI 3.1415926535898
APlaneGeometryCompute::APlaneGeometryCompute(void)
{
}
APlaneGeometryCompute::~APlaneGeometryCompute(void)
{
}
//角度转弧度
double Degree2Radius(double d)
{
double rlt = d*_PI / 180;
return rlt;
}
//弧度转角度
double Radius2Degree(double r)
{
double rlt = r * 180 / _PI;
return rlt;
}
//单位向量
AJZPoint2D AJZPoint2D::UnitVector(){
double len=sqrt(x*x+y*y);
if (len==0)
{
AJZPoint2D rlt=*this;
return rlt;
}
double xt=x/len;
double yt=y/len;
AJZPoint2D pt(xt,yt);
return pt;
}
//绕原点的逆时针方向角
double AJZPoint2D::ClockAngleByOrg(){
double angle=atan2(y,x);
if (angle
关注
打赏
最近更新
- 深拷贝和浅拷贝的区别(重点)
- 【Vue】走进Vue框架世界
- 【云服务器】项目部署—搭建网站—vue电商后台管理系统
- 【React介绍】 一文带你深入React
- 【React】React组件实例的三大属性之state,props,refs(你学废了吗)
- 【脚手架VueCLI】从零开始,创建一个VUE项目
- 【React】深入理解React组件生命周期----图文详解(含代码)
- 【React】DOM的Diffing算法是什么?以及DOM中key的作用----经典面试题
- 【React】1_使用React脚手架创建项目步骤--------详解(含项目结构说明)
- 【React】2_如何使用react脚手架写一个简单的页面?