0
$\begingroup$

If I have 4 points

        var x1;
        var y1;
        var x2;
        var y2;
        var x3;
        var y3;
        var x4;
        var y4;

that make up a box. So

(x1,y1) is top left
(x2,y2) is top right
(x3,y3) is bottom left
(x4,y4) is bottom right

And then each point has a weight ranging from $0-522$. How can I calculate a coordinate $(tx,ty)$ that lies inside the box, where the point is closer to the the place that has the least weight (but taking all weights into account). So for example. if $(x3,y3)$ has weight $0$, and the others have weight $522$, the $(tx,ty)$ should be $(x3,y3)$. If then $(x2,y2)$ had weight like $400$, then $(tx,ty)$ should be move a little closer towards $(x2,y2)$ from $(x3,y3)$.

Does anyone know if there is a formula for this? Thanks

  • 1
    So I guess "weighted center point" doesn't mean center of mass for you. I think you're going to have to come up with a better way of defining what you want.2017-02-28
  • 0
    I think another way to explain it is, imagine each corner has gravitational pull, If the weight is smaller, the pull is stronger (0 means max pull strength, 522 means no pull). Then if you drop a ball in the center, it will move based on which side has more pull. But at some location within the box, it will stabilize and stay still, where it feels an equal pull from all sides of it. That is the location I'm trying to find.2017-02-28
  • 0
    That's the center of mass. But if $(x_3, y_3)$ has weight $0$, then the center of mass won't be at that point -- it'll be closer to the opposite corner. What you're describing in your question sounds sorta like "negative" weight (but even the concept of a repulsive force doesn't quite do what you claim you want).2017-02-28
  • 0
    Yes negative weight, but regardless, is there a way to calculate this center of mass? For simplicity, we can just invert the weight values (522-weight), so make it easier to explain.2017-02-28
  • 1
    Center of mass is easy. What you say in your question is ill-defined (as far as I can tell).2017-02-28
  • 0
    How i'll defined though, I can try to explain better.2017-02-28
  • 0
    Is it possible just to reverse the roles of the numbers? Essentially a map that would send $522\mapsto0$ and $0\mapsto522$? Then your setup at least makes sense from a typical standpoint.2017-02-28
  • 0
    Yeah the inverse is fine if it makes the solution easier to explain2017-02-28
  • 0
    In general, weighting moves points *towards* the largest weight. To reverse that you could use something like $x = \left(\sum (522-w_i)x_i\right) / \sum w_i$. Of course, that's not the *only* way to do it.2017-02-28

2 Answers 2

0

Here's one way to get something like what you describe. I've written it as an algorithm, but I'm sure someone could go through and figure out a general mathematical expression for the final position of the "weighted" point in terms of the 4 initial points.

Algorithm

  1. Figure out the proportions of "weight" that each corner has compared to its opposite. So let's say TL (top left) has 100, TR has 200, BR has 300, and BL has 400. Then TL has 1/4 of the weight in its diagonal where BR has the other 3/4. And TR has 1/3 where BL has 2/3.
  2. Start WP ("weighted" point) at the TL. Move it along the TL-BR diagonal by the same proportion of the distance to BR as the proportional weight of TL.
  3. Figure out the line parallel to the diagonal TR-BL that passes through the current position of the WP. Also determine the intersections of that line with the boundary of the quadrilateral determined by the 4 points.
  4. Move WP along that line to the point where it intersects the top boundary of the quadrilateral.
  5. Move WP back down the line a distance such that the ratio of the distance moved to the distance to the other boundary point that intersects the line is just the proportional weight of TR.

Now WP should be where you want it.

Using my example from step 1, here's where the WP should be at each step assuming the four points are the vertices of the unit square.

  1. (1/4,3/4)
  2. (1/4,3/4)
  3. (1/2,1)
  4. (1/3,5/6)
0

Maybe you can try this (if there is at least one weight $w_i \neq 522$ ): $$v_i=522-w_i\\ tx=\frac{\sum{x_i v_i}}{\sum v_i}\\ ty=\frac{\sum{y_i v_i}}{\sum v_i}$$

If all weights $w_i$ are equal to $522$ (and $\sum v_i =0$), then the problem gets easier: $$tx=\frac{\sum{x_i }}{4}\\ ty=\frac{\sum{y_i}}{4}$$