Individual project work - the number of intersection graphics demand
- Teaching classes: 005
- Project Address: https://github.com/prime21/IntersectProject.git
project | content |
---|---|
This work belongs to the Northern Spring 2020 Software Engineering | Blog class connection Park |
This job is a personal project of the course work | Work requirements |
My aim in this course is | Harvest team project development experience, to improve their software development level |
In particular aspects of the job which helped me achieve goals | Experience pipeline MSCV development |
Problem-solving ideas
According to requirements description, we can get the software needed to run the process, in general, divided into three steps:
- Parse command line parameters, get the path of the input file and the output file
- Obtain input from the input file, and parses the graphic parameter stored in the corresponding data structure
- Solving the number of intersections between the pattern and outputs
- Intersection of two linear equations, the simultaneous
\ [A_1 x + y + B_1 C_1 = 0 \\ A_2 and B_2 + x + C_2 = 0 \]
解得
\[ X = \frac{B_1 C_2 - B_2 C_1} {A_1 B_2 - A_2 B_1} \\ Y = \frac{B_1 C_2 - B_2 C_1} {A_1 B_2 - A_2 B_1} \]
The intersection of two circles formula \ (C_1 (O_1, r_1) , C_2 (O_2, r_2) \)
Where disjoint \ [| O_1O_2 | <| r_1 -r_2 | \] or \ (| O_1O_2 |> r_1 + r_2 \)
In other cases, even investigated the relationship between the center line and the intersection of the vertical string, strings and even to find the intersections of the center line intersection \ (P \)
\(P = O_1 + \overrightarrow {i_{O_1O_2}} \times a\)
Where $ a = \ frac {r_1 ^ 2 - r_2 ^ 2 + d ^ 2} {2d} $
Then the intersection points in the vertical direction \ (P '= P \ pm \ overrightarrow j \ times h \)
\ (\ overrightarrow j \) is \ (\ overrightarrow i \) of the normal vector, \ (H = \ ^ R_1 sqrt {2 - A ^ 2} \)
And a straight line intersects the circle equation, considering the linear vector formula \ (U = T + U_0 (U_1-U_0) \) , for the circle \ (C (O, r) \)
By the \ (| uO | = r \ ) elimination to give \ (| u_0 + t (u_1 -u_0) - O | = r \) is about \ (T \) a quadratic equation, the solution was two \ (T \) , was the intersection
design
data structure
The basic types of vector operations
struct inter {
double x;
double y;
inter() { x = 0; y = 0; }
inter(double x, double y) : x(x), y(y) {}
inter(poi p) : x(p.first * 1.), y(p.second * 1.) {}
bool operator == (const inter& rhs) const {
return dcmp(x - rhs.x) == 0 && dcmp(y - rhs.y) == 0;
}
bool operator < (const inter& rhs) const {
int d = dcmp(x - rhs.x);
if (d < 0) return true;
if (d > 0) return false;
if (dcmp(y - rhs.y) < 0) return true;
return false;
}
friend inter operator + (const inter& lhs, const inter& rhs) {
return inter(lhs.x + rhs.x, lhs.y + rhs.y);
}
friend inter operator - (const inter& lhs, const inter& rhs) {
return inter(lhs.x - rhs.x, lhs.y - rhs.y);
}
friend inter operator / (const inter& lhs, const double& d) {
return inter(lhs.x / d, lhs.y / d);
}
friend inter operator * (const inter& lhs, const double& d) {
return inter(lhs.x * d, lhs.y * d);
}
friend double operator * (const inter& lhs, const inter& rhs) {
return lhs.x * rhs.x + lhs.y * rhs.y;
}
double length() {
return sqrt(x * x + y * y);
}
double length2() {
return x * x + y * y;
}
};
Complexity Analysis
Taking into account all the lines and enumerate the case intersects the circle, and all intersection sorting complexity is \ (O (n ^ 2 + m \ log m) \) where \ (n-\) is the number of lines and circles, \ (m \) is the number of intersections.
Code
Code Organization
Three kinds of the intersection of function
void addLineInter(int i, int j) {
line *lhs = (line *)(pro[i]);
line *rhs = (line *)(pro[j]);
long long D = (lhs->A * rhs->B) - (rhs->A * lhs->B);
if (D == 0) return ;
double xx = (lhs->B * 1. * rhs->C) - (rhs->B * lhs->C);
double yy = (lhs->A * 1. * rhs->C) - (rhs->A * lhs->C);
gb_in.push_back(inter(xx / D, yy / D));
}
void addCircleInter(int i, int j) {
circle* lhs = (circle*)(pro[i]);
circle* rhs = (circle*)(pro[j]);
long long dis = (lhs->o.first - rhs->o.first) * (lhs->o.first - rhs->o.first) + (lhs->o.second - rhs->o.second) * (lhs->o.second - rhs->o.second);
if (dis > (lhs->r + rhs->r) * (lhs->r + rhs->r)) return;
if (dis < (lhs->r - rhs->r) * (lhs->r - rhs->r)) return;
double alpha = dis + lhs->r * lhs->r - rhs->r * rhs->r;
alpha /= 2 * sqrt(dis);
double h = std::sqrt(lhs->r * lhs->r - alpha * alpha);
inter o1o2 = inter(rhs->o) - inter(lhs->o);
o1o2 = o1o2 / o1o2.length();
inter vert = inter(o1o2.y, -o1o2.x);
inter P = inter(lhs->o) + o1o2 * alpha;
inter Q = P + vert * h;
gb_in.push_back(Q);
Q = P - vert * h;
gb_in.push_back(Q);
}
void addLcInter(int i, int j) {
line* lhs = (line*)(pro[i]);
circle* rhs = (circle*)(pro[j]);
inter li = inter(lhs->b) - inter(lhs->a);
inter lc = inter(lhs->a) - inter(rhs->o);
double A = li.length2();
double B = (lc * li) * 2;
double C = lc.length2() - (rhs->r) * (rhs->r);
double delta = B * B - 4 * A * C;
if (delta >= 0) {
delta = sqrt(delta);
double x1 = (delta - B) / (2 * A);
double x2 = (-delta - B) / (2 * A);
inter t1 = inter(lhs->a) + li * x1;
inter t2 = inter(lhs->a) + li * x2;
gb_in.push_back(t1);
gb_in.push_back(t2);
}
}
Return Value treated under different conditions
test
OpenCPPCoverage
Code quality analysis
Reshaper C++
Performance Improvements
Hindsight
As the demand of this task is to determine, there is no need to place too much speculation, and therefore needs less time spent on analysis.
PSP table
PSP2.1 | Personal Software Process Stages | Estimated time consuming (minutes) | The actual time-consuming (minutes) |
---|---|---|---|
Planning | plan | ||
· Estimate | • Estimate how much time this task requires | 5 | 5 |
Development | Develop | ||
· Analysis | · Needs analysis (including learning new technologies) | 15 | 15 |
· Design Spec | Generate design documents | 10 | 10 |
· Design Review | · Design Review (and his colleagues reviewed the design documents) | 0 | 0 |
· Coding Standard | · Code specifications (development of appropriate norms for the current development) | 0 | 0 |
· Design | · Specific design | 60 | 90 |
· Coding | · Specific coding | 240 | 240 |
· Code Review | · Code Review | 10 | 10 |
· Test | · Test (self-test, modify the code, submit modifications) | 60 | 60 |
Reporting | report | ||
· Test Report | · testing report | 10 | 10 |
· Size Measurement | · Computing workload | 10 | 10 |
· Postmortem & Process Improvement Plan | · Hindsight, and propose process improvement plan | 30 | 30 |
total | 450 | 480 |