2

假设我在笛卡尔坐标平面上有两个点,A并且B,其xy坐标是双精度floats。如何找到C它们之间距离的任意百分比的点的位置?

换句话说,以下方法中的内容是什么而不是“ //Do magic to C”?请记住,AandB每个都由两个doubles 组成,它们分别代表它们的xy坐标。

public static findProgressPoint(DoublePoint A, DoublePoint B, double position)
{
  if (position > 1 || position < 0) //Ensure that position is between 0 and 1, inclusive
    position = position - (int)position;
  DoublePoint C = new DoublePoint(0.0, 0.0);
  //Do magic to C
  return C;
}
4

2 回答 2

4

这应该有效:

double px = x1 + (x2-x1)*position;
double py = y1 + (y2-y1)*position;
DoublePoint C = new DoublePoint(px, py);

px是与的值成比例的距离x之间的坐标;是对应的坐标。x1x2x1positionpyy

于 2012-11-15T00:54:08.810 回答
1
DoublePoint C = new DoublePoint( position * (A.x + B.x), position * (A.y + B.y) );
于 2012-11-15T00:55:24.533 回答