计算斜率已知的直线上的下一个点 [英] compute next point on a line with known slope

查看:140
本文介绍了计算斜率已知的直线上的下一个点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据直线方程y =(m * x)+ c.如果我知道斜率(m)并且我知道那条线穿过一个点(cx,cy).我想知道cx,cy之前和之后同一行上的下一个点,该如何计算它们.

according to the line equation y = (m * x ) + c. if I know the slope(m) and I know that the line pass through a point(cx, cy). I want to know the next points on the same line before and after cx, cy, how do I go about to compute them.

推荐答案

在C ++中:

通过计算其他点

extrapolate line(m, cx, cy);
double y_before  = line.y(cx - 1);  // for example
double y_after   = line.y(cx + 1);

http://ideone.com/BELNc 上观看(两个示例)

struct extrapolate
{
     extrapolate(double slope, double x1, double y1) 
         : _slope(slope), _x1(x1), _y1(y1) 
     {
     }

     double y(double x) const // return y for given x
     {
          return _y1 + (x-_x1)*_slope;                  
     }

  private:
     double _slope, _x1, _y1;
};

这篇关于计算斜率已知的直线上的下一个点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆