Finding a 3rd point from 2 known points


How do you find a point that is located n-percent along the line defined by points A and B?


Not percent… but between 0.0 and 1.0

percent = 0.5
midVec = (vecApercent) + (vecb(1-percent))

import Blender
# ME is supposed to be a mesh 
# for the example, get the two first vertices of ME  
# for the example, a list of values for "percent"
# this will create 4 point on the edges [AB]
for percent in [10,20,45,75]  :
  # create a vertex to be added to the mesh
  # Calculate the location of C between A and B, in x,y and z axis . 
  # like that : C=A+(B-A)*percent
  for n in [0,1,2]:[n][n]+([n][n])*percent/100.0
  # have an echo in the console
  # Add new vertex to the list 
# insert the new data of ME  in Blender daat base .

variant version :

Of course both these answers are right

but why can’t I do?

a = Vector(1,2,3)
vv = Blender.NMesh.Vert() = a

( you would like to think that cambos = .5a + .5b
would work but it fails)

Apparently and a are both type <vector>

whereas the syntactically obscure

a = Vector(1,2,3)
vv = Blender.NMesh.Vert()[:] = a[:]


The wonderfool vectors’ world . This works :

Sure these all work but what one’s intuition tells one
should work fails – ie mixing Cambo’s code with
the Vert() constructor

1/ the Vert constructor (still) doesn’t take a <vector> object
where it really should - I hate working with indices

2/ type( should be polymorphic to a <vector>
but the assignment fails with a (not very useful)
Attribute error.

I know it’s not read only as[:] = a[:] works

you cant do…
you have to assign the x/y/z
co=… = co.x = co.y = co.z

Assigning slices works but is less explicit than your code
and therefore (Pythonically) worse.
BTW I think the .x, .y, .z attributes are great…

I can see why the assignment = co
shouldn’t work as it might only pass a reference
but none of this is clear in the api doc.
And (I suppose I should post this in LetterRips request thread)
The Vert constructor should really take a <vector>.

Here’s a code snippet to test.
it’s a hack to create a mesh
for reading the head position after the IK/IPOs/parenting
is evaluated.

import Blender
from Blender import Armature as AA

sk = Blender.Object.Get("sk") #sk = aramture
skd = sk.getData()

plane = Blender.Object.Get("yplane").getData() #some mesh object "yplane"
for gp in plane.getVertGroupNames():
verts = []

for bone,data in skd.bones.items():
	xx = data.head['ARMATURESPACE']
	vv= Blender.NMesh.Vert(0,0,0)[:] = xx[:]
plane.verts = verts
for i,bone in enumerate(skd.bones.keys()):