# calculate coordinates on line between 2 coordinates

**URL:** <https://blenderartists.org/t/calculate-coordinates-on-line-between-2-coordinates/561035>\
**Category:** Python Support\
**Created:** [January 1, 2013, 12:08pm UTC](https://blenderartists.org/t/calculate-coordinates-on-line-between-2-coordinates/561035 "2013-01-01T12:08:10Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![sc3sc3](https://blenderartists.org/letter_avatar_proxy/v4/letter/s/e56c9b/32.png) [@sc3sc3](https://blenderartists.org/u/sc3sc3)\
**Post date:** [January 1, 2013, 12:08pm UTC](https://blenderartists.org/t/calculate-coordinates-on-line-between-2-coordinates/561035/1 "2013-01-01T12:08:10Z")

</div>

hi

i have 2 coordinates being ( x, y, y ) and ( i, j, k )

i divide the straight line that connect ( x, y, y ) and ( i, j, k ) into for example 6 equal parts  
and would like to calculate the coordinates of those points

i think i found some solutions for 2d:

> <https://stackoverflow.com/questions/10825174/calculate-next-point-on-2d-linear-vector>

  
[http://www.cocos2d-iphone.org/forum/topic/33889](http://www.cocos2d-iphone.org/forum/topic/33889)

but does anybody know how to do this for 3d ?

thanks for any help  
greetings  
sc3

---

<div class="post-metadata">

**Author:** ![Terry](https://blenderartists.org/letter_avatar_proxy/v4/letter/t/b9e5f3/32.png) [@Terry](https://blenderartists.org/u/Terry)\
**Post date:** [January 1, 2013, 2:10pm UTC](https://blenderartists.org/t/calculate-coordinates-on-line-between-2-coordinates/561035/2 "2013-01-01T14:10:11Z")

</div>

Given two points in 3d, p1 and p2, define a vector v as p2 - p1.  
Normalize v so that the length is one.  
Then the infinite number of points on the line segment between p1 an p2 is defined by p1 + dv where d is any value between zero and the distance between  
p1 and p2.

---

<div class="post-metadata">

**Author:** ![agoose77](https://blenderartists.org/user_avatar/blenderartists.org/agoose77/32/442949_2.png) [@agoose77](https://blenderartists.org/u/agoose77)\
**Post date:** [January 1, 2013, 2:17pm UTC](https://blenderartists.org/t/calculate-coordinates-on-line-between-2-coordinates/561035/3 "2013-01-01T14:17:21Z")

</div>

This is actually mathematically quite simple when you think about it.

The line AB as we shall call it is simply a vector comprised of an X, Y and Z component.

dX (the x component) = Bx - Ax  
dY = By - Ay  
dZ = Bz - Az

Let’s argue you were looking for the midpoint. Well, the midpoint is exactly halfway between A and B, and as A to B is a vector made up of components, the midpoint is half each component. (A + .5 \* (B - A))

So, the same applies for any fraction of the vector. Thus, splitting it into six parts is just taking each sixth of the vector.  
With mathutils (the default blender maths lib) we don’t even have to bother doing component operations, we can multiply the entire vector by a scalar:

```auto

from mathutils import Vector

a = Vector((0, 0, 0))
b = Vector((3, 3, 3))

difference = (b - a)

a_sliced = [(difference / 6) * (i + 1) for i in range(6)]

print(a_sliced)

```

---

<div class="post-metadata">

**Author:** ![sc3sc3](https://blenderartists.org/letter_avatar_proxy/v4/letter/s/e56c9b/32.png) [@sc3sc3](https://blenderartists.org/u/sc3sc3)\
**Post date:** [January 1, 2013, 2:48pm UTC](https://blenderartists.org/t/calculate-coordinates-on-line-between-2-coordinates/561035/4 "2013-01-01T14:48:44Z")

</div>

thanks for the responses  
i will try those out tomorrow

---

<div class="post-metadata">

**Author:** ![CoDEmanX](https://blenderartists.org/letter_avatar_proxy/v4/letter/c/77aa72/32.png) [@CoDEmanX](https://blenderartists.org/u/CoDEmanX)\
**Post date:** [January 2, 2013, 9:58am UTC](https://blenderartists.org/t/calculate-coordinates-on-line-between-2-coordinates/561035/5 "2013-01-02T09:58:54Z")

</div>

you can also use the lerp function:

```auto
slices = 6

v1 = Vector((0,0,0))
v2 = Vector((6,0,0))

v_sliced = [v1.lerp(v2, (i+1)/slices) for i in range(slices)]

```

---

<div class="post-metadata">

**Author:** ![sc3sc3](https://blenderartists.org/letter_avatar_proxy/v4/letter/s/e56c9b/32.png) [@sc3sc3](https://blenderartists.org/u/sc3sc3)\
**Post date:** [January 12, 2013, 9:13am UTC](https://blenderartists.org/t/calculate-coordinates-on-line-between-2-coordinates/561035/6 "2013-01-12T09:13:36Z")

</div>

thanks @CoDEmanX  
the lerp function is essential if you go from positive to negative coordinates

regards
