Python, making a vector from 2 points

so, I know I can have an object tell me a vector from itself to another object or point. in blenderpython 2.7ese this is KXGameObject.getVectTo([point] or KXGameObject)

but now I’m stumped on how to generate the same sorta thing when I have no game object at a point and want to get a vector from that point to another point.

I looked up the math to do it, people said you subtract the starting point from the point you want to get to.

but this does not work in a real game environment because we have negative 3D space. So if I wanted to calculate the vector from [0,1,2] to [1,-1,1] subtracting 0,1,2 would give me a vector of [1 - 0 =0, -1 -1 = -2, 1-2 = -1] [0, -2, -1]

This would be incorrect. having an object point an axis at this vector would be the wrong angle.

How can I code around this?

if you use python 3.0 + thats fine. Either will give me the basic info I need and I can translate it back.

thanks.

Of course it does work. Why would there be a problem with negative values?
Are you sure you are calculating what you want? Also try to calculate correctly 1 - 0 is not 0;

a = [0, 1, 2];
b = [1, -1, 1];

If you want a vector pointing from a -> b (Destination b - Source a):
c = b - a;
c = [1, -1, 1] - [0, 1, 2];
c = [1, -2, -1];

That is the Vector between them.

To demonstrate:
If you were at point a and wanted to get to point b you’d have to move this distance c to reach it.
a + c = b;
[0, 1, 2] + [1 , -2, -1] = b = [1, -1, 1];

1 Like

The principles of linear algebra work the same in Blender as they do in Unity or Unreal or Frostbite or pencil and paper. this is fundamental mathematics… Your statement is akin to saying “2+2 does not equal 4 in this engine because we use DirectX”.

oops, sorry, 1-0=1 did that post in a hurry.

I suppose the reason I did not think it worked is because when I put an object at these same points and had it give me the vector between itself and the point listed, blender gave me an entirely different list of numbers:

[0.40824829046386307, -0.81649658092772615, -0.40824824829046386307]

to me, blender’s vector makes 0 sense whatsoever unless it’s proportionately scaling the number down to it’s lowest possible value… but the fact it was different made me think I was doing something wrong.

The result from blender is only the direction, that means it has normalized the vector to a length of 1.

ah, so if the vector were [10, 8, 4] blender would normalize it to [1, 0.8, 0.4] ?

that makes sense.

No, normalizing means dividing by the length. The length of (10, 8, 4) is 13,416… so the normalized vector would be about (0,745; 0,596; 0,298)

yeah I meant as in blender/python where “,” separates numbers in a list so [10 then 8 then 4] so I assume it would then get the length by calculating the hypotenuse from the origin to this point, then divide each part by the hypotenuse.

ok. if that’s the case, it’s extra math steps, probably not needed in the big picture of things.