问题描述:

I am writing the program in Cocoa but I think that the solution must be quite universal.

I have a set of points represented by 3D vectors. Each point has a weight assigned to it. The weight is in the range from 0 to 1. The sum of all weights isn't equal to 1.

How should the weighted mean point be calculated from such set?

Either programmatic or pure mathematical solution will be helpful.

Of course if Cocoa has some specific tools for solving this task, I would very appreciate this information.

Simply sum all vectors scaled by their weight. Finally, divide by the sum of all weights. This has the same effect as first normalizing all weights to sum to 1.

Pseudo-code:

```
sum = [0, 0, 0]
totalWeights = 0
for each point p with associated weight w:
sum += p * w
totalWeights += w
mean = sum / totalWeights
```

您可能感兴趣的文章：

- opengl es - How many Android devices support GLSurfaceView.setPreserveEGLContextOnPause today?
- c++ - Interfaces and child classes
- c++ - Can I get an exception object's type name in the catch(...) block?
- objective c - Converting NSDate from a calendar to another
- c++ - Check length char[] befor converting to wstring()
- php - Reading a specific line from a text file
- clr - Any implementation of an Unrolled Linked List in C#?
- Finding Hudson Log Files
- Forward to a payment-gateway together with POST data using cURL (or any other PHP server side solution)
- WCF in Winforms app - is it always single-threaded?

随机阅读：

**推荐内容**-

**热点内容**