【发布时间】:2014-11-18 05:52:55
【问题描述】:
我正在研究使用 x 轴上的数据点识别交叉点的算法。我可以理解计算,但无法理解此计算的目的。据我了解,它每次都会确定新的 y 点和斜率并减去它们。 我也想插入图片,但我没有 10 个声望点。 如果我需要提供信息,请告诉我。
//This function determine the crossing point when the graph is intersecting x axis.
XPoint findXingPoint(Curve & curve, double rfix, double vcc, int type, int pull_up)
{
//curve class contain x and y data point
// rfix is fixed value which is generally 50
// vcc also fix value
// type contain 0 and 1
//pull up to identify graph
XPoint p = { 0.0, 0.0 };
double r_fix = rfix;
double m = -1 / r_fix;
double c = vcc / r_fix;
if(type)
c=0;
double r, s, X1, X2, Y1, Y2, Y3, Y4;
r = (m * curve[0].first) + c;
// r is a kind of y value which determine from x and y point
s = abs(r);
for (Curve::iterator i = curve.begin(); i != curve.end(); i++) {
curve_point p = (*i);
double xcurve = p.first;
double ycurve = p.second;
double yloadline = m * xcurve + c;
double B = ycurve - yloadline;
if (B >= 0 && r >= B) {
r = B;
X1 = xcurve;
Y1 = yloadline;
Y2 = ycurve;
}
if (B <= 0 && r >= abs(B)) {
s = abs(B);
X2 = xcurve;
Y4 = yloadline;
Y3 = ycurve;
}
}
#could not understand purpose of B calculation
if (s == 0)
X1 = X2;
if (r == 0)
X2 = X1;
if (X1 != X2) {
double m1, m2, c1, c2;
m1 = (Y3 - Y2) / (X2 - X1);
m2 = (Y4 - Y1) / (X2 - X1);
c1 = Y3 - (m1 * X2);
c2 = Y4 - (m2 * X2);
// CASE m1==m2 should be handled.
p.x = (c2 - c1) / (m1 - m2);
p.y = (m2 * p.x) + c2;
} else {
p.x = X1;
p.y = Y1;
}
#not able to also understand calculation
if (verbosityValue >= 1)
loginfo<<"found crossing point @ " << p.x << " " << p.y << endl;
return p;
}
Output:
first
found crossing point @ 7.84541e-08 -1.96135e-09 with type 0
found crossing point @ 0.528564 0.0182859 with type 1
second
found crossing point @ 0.654357 -0.0163589 with type 0
found crossing point @ 1.25827 4.31937e-05 with type 1
【问题讨论】:
-
给你的图片一个链接,有人会编辑(甚至可能是我):P。此外,您需要改进您的问题,目前还不清楚。
-
真正的代码也不错。这不是 C++ 代码;
#不是 C++ 中的注释字符
标签: c++ algorithm graph linear-algebra