How to calculate points between two given points and a given distance?

I have a point A (35.163 , 128.001)and a pointB (36.573 , 128.707)

I need to calculate the points lying at point A and point B

using the standard formula for the distance between two points, I found D = 266.3

each of the points lies inside the line AB (the black point p1, p2, ... p8) are separated with equal distance d = D / 8 = 33.3

How could I calculate X and Y for p1, p2, ... p8?

Java or C # language example is welcome

or just point me to a formula or method.

Thanks.

** The above calculation is actually used to calculate the fictitious point point for the shaded level on my map and to specify the interpolation of the shaded area *

find the X and Y for all the points between A and B

+4
source share
5

:

// I've used Tupple<Double, Double> to represent a point;
// You, probably have your own type for it
public static IList<Tuple<Double, Double>> SplitLine(
  Tuple<Double, Double> a, 
  Tuple<Double, Double> b, 
  int count) {

  count = count + 1;

  Double d = Math.Sqrt((a.Item1 - b.Item1) * (a.Item1 - b.Item1) + (a.Item2 - b.Item2) * (a.Item2 - b.Item2)) / count;
  Double fi = Math.Atan2(b.Item2 - a.Item2, b.Item1 - a.Item1);

  List<Tuple<Double, Double>> points = new List<Tuple<Double, Double>>(count + 1);

  for (int i = 0; i <= count; ++i)
    points.Add(new Tuple<Double, Double>(a.Item1 + i * d * Math.Cos(fi), a.Item2 + i * d * Math.Sin(fi)));

  return points;
}

...

IList<Tuple<Double, Double>> points = SplitLine(
  new Tuple<Double, Double>(35.163, 128.001),
  new Tuple<Double, Double>(36.573, 128.707),
  8);

():

(35,163, 128,001)                    // <- Initial point A
(35,3196666666667, 128,079444444444)
(35,4763333333333, 128,157888888889)
(35,633, 128,236333333333)
(35,7896666666667, 128,314777777778)
(35,9463333333333, 128,393222222222)
(36,103, 128,471666666667)
(36,2596666666667, 128,550111111111)
(36,4163333333333, 128,628555555556)
(36,573, 128,707)                    // <- Final point B
+3

, .

        PointF pointA, pointB;

        var diff_X = pointB.X - pointA.X;
        var diff_Y = pointB.Y - pointA.Y;
        int pointNum = 8;

        var interval_X = diff_X / (pointNum + 1);
        var interval_Y = diff_Y / (pointNum + 1);

        List<PointF> pointList = new List<PointF>();
        for (int i = 1; i <= pointNum; i++)
        {
            pointList.Add(new PointF(pointA.X + interval_X * i, pointA.Y + interval_Y*i));
        }
+5

A - (x a, y a), B - (x b, y b > )

alpha = tan -1 ((y b - y a)/(x b - x < > > ))

p1 = (x a + d * cos (alpha), y a + d * sin (alpha))

p k= (x a + kd * cos (alpha), y a + kd * sin (alpha)), k = 1 7

( )

+2

A B, , A B. A. ( , , , 1.0/9.0.) - , , :

vec2 A = vec2 (35.163, 128.001);
vec2 B = vec2 (36.573, 128.707);
vec2 V = B - A;
for (i = 1; i < 8; i++) {
    vec2 p[i] = A + V * (float)i / 8.0;
}

(, Java, #.)

+2

It will not be very difficult in C # or java. Once you understand the logic, you will find pleasure, realized in its own way.

0
source

All Articles