This site uses strictly necessary cookies. More Information

X- Home /

# Get the point between 2 other points using weights

Hello. I have another algorithm issue.

I have 2 weights.

Weight 1 (W1) is between 0 and 1.

Weight 2 (W2) is the "opposite" of W1. W2 = Mathf.Abs(W1 - 1.0f)

I have 2 points.

When W1 is 1.0 the final point is Point 1.

When W2 is 1.0 the final point is Point 2.

When W1 and W2 is 0.5 the final point is the midpoint of Point 1 and Point 2.

**Answer** by alexi123454
·
Jul 22, 2015 at 05:01 PM

How many dimensions is your point? If it's 2 dimensional, you can use Vector2.Lerp(Point1, Point2, W2). For 3 dimensional points, you can use the same function with Vector3.

If you don't want to use the built in functions, the mathematics behind it are as such:

```
vectorBetweenPoints = Point2 - Point1;
finalValue = Point1 + (vectorBetweenPoints * W2);
```

Oh yes. Thank you that is perfect. (By the way I am using Vector3).

That's correct. Since you're saying that W2 being at 1.0 should be the second point, you should use W2 in the math.

You could use W1 ins$$anonymous$$d, if you switch things around so that Point2 is the first value, and Point1 as the second value.

### Your answer

### Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.