【问题标题】:nFinding Xcrossing point using Data Pointsn 使用数据点查找 Xcrossing 点
【发布时间】: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


【解决方案1】:

这似乎是一个简单的实现。对于曲线上的给定点x,y,找到斜率,画一条穿过斜率的线,找到该线与 x 轴相交的位置,然后在该点找到新的 y 值。对于表现良好的函数,新的 y 值比初始 y 值更接近 0。你迭代直到近似值足够好。

如果您查看图表,您会发现中间部分非常笔直。因此,线的斜率是曲线的局部良好近似值,并且您的新 y 值更接近于零(至少 10 倍,可能是 100 倍,查看图表。0。如果您从更陡峭的两边都有斜坡,你需要多走一步。你的第二个 x 点将在中间部分。

【讨论】:

  • 感谢您的回复。但是我有一个问题,当我们有类型 1 时,我们得到适当的值,但如果 type=0,我们得到完全不同的值。无法理解类型 0 和 1 的 c 值
  • type=0时,c来源于vcc; type = 1 c 是从 vcc 派生的。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-05-09
  • 2011-01-21
  • 2011-07-03
  • 2022-10-24
  • 2019-09-17
  • 1970-01-01
相关资源
最近更新 更多