-3

I am writing a javascript program to find the midpoint of the rectangle (diagonal lines which intersect in the middle) I have 8 co-ordinates (x1,y1) (x2,y2) (x3,y3) (x4,y4). How can i achieve this?

umzee
  • 11
  • 1
  • 6

2 Answers2

0

Just find the average of each coordinate. Because it’s a rectangle, you only need two coordinates. If x1, y1 is opposite x3, y3 then the midpoint is ((x1+x3)/2, (y1+y3)/2)

paper man
  • 488
  • 5
  • 19
  • Can you kindly simplify more? Here is the list of my coordinates 134.2 = x1 174.1=x2 134.2=x3 174.1 =x4 741.4=y1 741.4=y2 725.6=y3 725.6=y4 – umzee Nov 19 '17 at 14:50
  • @umzee ((134.2+174.1)/2, (741.4+725.6)/2) = (154.15, 733.5) – paper man Nov 19 '17 at 14:56
0

Midpoint of a triangle is the midpoint of each diagonal. So, the midpoint is:

x_mid = (x1 + x3)/2; // or (x2 + x4)/2
y_mid = (y1 + y3)/2; // or (y2 + y4)/2
OmG
  • 18,337
  • 10
  • 57
  • 90