我有一个问题,我知道一条线,我只知道它的斜率(m)和它上面的一个点A(x,y)我如何计算这条线上的点(实际上是两条点)距离(d)点一个 ???我问这个是为了找到一条穿过A(x,y)的线上的像素强度,距离是这样.在这种情况下,距离将是像素数.
我很疯狂地计算沿着给定线AB的点,在离A的给定距离处,这样我就可以"绘制"两个给定点之间的线.一开始听起来很简单,但我似乎无法做到这一点.更糟糕的是,我不明白我哪里出错了.几何(和一般的数学)不是我强大的套件.
我已经阅读了类似的问题,并在那里有答案.事实上,我直接从Mads Elvheim的回答中解除了我对CalculatePoint函数的当前实现:给定一个起点和终点,以及一个距离,计算沿线的一个点(加上后面的注释中的修正 - 如果我理解正确的话)因为我的独立尝试解决问题让我无处可去,除了一流的快递票务frusterpationland.
这是我的更新代码(请参阅EDIT备注帖子的底部):
using System;
using System.Drawing;
using System.Windows.Forms;
namespace DrawLines
{
public class MainForm : Form
{
// =====================================================================
// Here's the part I'm having trouble with. I don't really understand
// how this is suposed to work, so I can't seem to get it right!
// ---------------------------------------------------------------------
// A "local indirector" - Just so I don't have go down and edit the
// actual call everytime this bluddy thing …Run Code Online (Sandbox Code Playgroud) 
我的程序中目前有以下行。我还有另外两个整数变量,x和y。
我想看看这个新点是否(x, y)在这条线上。我一直在看以下主题:
我想出了以下几点:
if(x >= x1 && x <= x2 && (y >= y1 && y <= y2 || y <= y1 && y >= y2))
{
float vx = x2 - x1;
float vy = y2 - y1;
float mag = sqrt(vx*vx + vy*vy);
// need to get the unit vector (direction)
float dvx = vx/mag; // this would be the unit vector (direction) x for the line
float dvy = …Run Code Online (Sandbox Code Playgroud)