资源简介

x线段绘制,并且可以选中线段的起点或者终点,选中后可以拖动重新进行定位

资源截图

代码片段和文件信息

#include “Graphbase.h“
#include 
#include 

double dist(PointEx p1 PointEx p2) {
return(sqrt((p1.x - p2.x)*(p1.x - p2.x) + (p1.y - p2.y)*(p1.y - p2.y)));
}

bool equalPoint(PointEx p1 PointEx p2) {
return ((fabs(p1.x - p2.x)}

double multiply(PointEx sp PointEx ep PointEx op) {
return((sp.x - op.x)*(ep.y - op.y) - (ep.x - op.x)*(sp.y - op.y));
}

double dotMultiply(PointEx p1 PointEx p2 PointEx p0) {
return ((p1.x - p0.x)*(p2.x - p0.x) + (p1.y - p0.y)*(p2.y - p0.y));
}

bool online(LineSegment l PointEx p) {
return((multiply(l.endPoint p l.startPoint) == 0) 
   && (((p.x - l.startPoint.x)*(p.x - l.endPoint.x) <= 0) && ((p.y - l.startPoint.y)*(p.y - l.endPoint.y) <= 0)));
}

PointEx rotate(PointEx o double d PointEx p) {
PointEx tp;
p.x -= o.x;
p.y -= o.y;
tp.x = p.x*cos(d) - p.y*sin(d) + o.x;
tp.y = p.y*cos(d) + p.x*sin(d) + o.y;
return tp;
}

double angle(PointEx o PointEx s PointEx e) {
double cosfi fi norm;
double dsx = s.x - o.x;
double dsy = s.y - o.y;
double dex = e.x - o.x;
double dey = e.y - o.y;

cosfi = dsx*dex + dsy*dey;
norm = (dsx*dsx + dsy*dsy)*(dex*dex + dey*dey);
cosfi /= sqrt(norm);

if (cosfi >= 1.0) return 0;
if (cosfi <= -1.0) return -3.1415926;

fi = acos(cosfi);
if (dsx*dey - dsy*dex > 0) return fi;      // 说明矢量os 在矢量 oe的顺时针方向 
return -fi;
}

double relation(PointEx p LineSegment l) {
LineSegment tl;
tl.startPoint = l.startPoint;
tl.endPoint = p;
return dotMultiply(tl.endPoint l.endPoint l.startPoint) / (dist(l.startPoint l.endPoint)*dist(l.startPoint l.endPoint));
}

PointEx perpendicular(PointEx p LineSegment l) {
double r = relation(p l);
PointEx tp;
tp.x = l.startPoint.x + r*(l.endPoint.x - l.startPoint.x);
tp.y = l.startPoint.y + r*(l.endPoint.y - l.startPoint.y);
return tp;
}

double pToLinesegDist(PointEx p LineSegment l PointEx &np) {
double r = relation(p l);
if (r<0) {
np = l.startPoint;
return dist(p l.startPoint);
}
if (r>1) {
np = l.endPoint;
return dist(p l.endPoint);
}
np = perpendicular(p l);
return dist(p np);
}

double pToLDist(PointEx p LineSegment l) {
return fabs(multiply(p l.endPoint l.startPoint)) / dist(l.startPoint l.endPoint);
}

double pToPointSet(int vcount PointEx pointset[] PointEx p PointEx &q) {
int i;
double cd = double(INF) td;
LineSegment l;
PointEx tq cq;

for (i = 0; i < vcount - 1; i++) {
l.startPoint = pointset[i];

l.endPoint = pointset[i + 1];
td = pToLinesegDist(p l tq);
if (td < cd) {
cd = td;
cq = tq;
}
}
q = cq;
return cd;
}

bool circleInsidePolygon(int vcount PointEx center double radius PointEx polygon[]) {
PointEx q;
double d;
q.x = 0;
q.y = 0;
d = pToPointSet(vcount polygon center q);
if (d < radius || fabs(d - radius) < EP)
return true;
else
return false;
}

double cosine(LineSeg

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2018-09-16 11:58  Debug\
     文件        1319  2018-09-16 11:58  Debug\MyGraphCal.Build.CppClean.log
     文件          95  2018-09-16 11:58  Debug\MyGraphCal.log
     目录           0  2018-09-16 12:25  Debug\MyGraphCal.tlog\
     目录           0  2018-09-16 12:25  GeneratedFiles\
     文件       38546  2018-09-15 16:49  Graph.h
     文件       25856  2018-09-15 16:49  Graphbase.cpp
     文件       13243  2018-09-15 16:49  Graphbase.h
     文件        6086  2018-09-16 10:50  MyGraphCal.cpp
     文件        1166  2018-09-16 10:38  MyGraphCal.h
     文件          70  2018-09-15 16:50  MyGraphCal.qrc
     文件        1055  2018-09-15 19:42  MyGraphCal.ui
     文件        9185  2018-09-15 16:51  MyGraphCal.vcxproj
     文件        2531  2018-09-15 16:51  MyGraphCal.vcxproj.filters
     文件         751  2018-09-16 08:56  MyGraphCal.vcxproj.user
     目录           0  2018-09-16 12:25  Resources\
     文件         191  2018-09-15 16:50  main.cpp

评论

共有 条评论