0 down vote [favorite](http://stackoverflow.com/questions/14624474/plotting-a-vector-via-a-script-in-blender-python#) <b>1</b> I want to plot a vector in the form xi+yj+zk at a position (a,b,c). This is a repost from a very quite blender forum.
This code is pretty near but it misses the origin by a little bit, (maybe about 0.1?). Can anyone see where I am going wrong.
The code assumes that I am correct that the three rotation parameters work like this.
p is an angle in the zy plane measured from z toward y,
q is an angle in the zx plane measured from z toward x.
r seems to have no effect at all.
import bpy; #plot the vector 4i-2j-3k from the origin as a thin cylinder import math; from math import *; x=4 y=-2 z=-3 length=sqrt(z*z+y*y+x*x) cog=length/2; bpy.ops.mesh.primitive_cylinder_add(vertices=16, radius=0.01, depth=length, end_fill_type='NGON', view_align=False, enter_editmode=False, location=(x/2,y/2,z/2), rotation=(atan(y/x),atan(x/z),0));
So far as I can tell, the way to create a line in Blender is to use a long thin cube or cylinder. The API for Blender/Python gives a cube / cylinder as this syntax
bpy.ops.mesh.primitive_cube_add(view_align=False, enter_editmode=False, location=(0,0,0), rotation=(0, 0, 0)) bpy.ops.mesh.primitive_cylinder_add(vertices=64, radius=0.01, depth=4, end_fill_type='NGON', view_align=False, enter_editmode=False, location=(0, 0 , 4/2), rotation=(0, 0, 0))
I know the position is at the cog and can handle the transform to do that but can’t work out how to transform my components into a rotation. I cannot see from the api what the definition of the rotation parameter is.
I have tried splitting long code lines with returns for clarity
A pointer to a resource would be fine if it has some code in it.