mathutils module has a number of classes and methods to deal with linear algebra requirements. See
mathutils.geometry for methods to find intersections and closest points of points, lines and planes. (Maybe handy re other question)
Blender comes with a python console, used below to demonstrate one way to construct the vector in question,
Start with the X axis as a basis vector
>>> x_axis = Vector((1, 0, 0))
Next make a matrix to rotate it around the Y axis to obtain any vector on XY plane, going thru (0, 0, 0).
>>> R = Matrix.Rotation(radians(23), 4, 'Y')
>>> v = (R @ x_axis).normalized()
Vector((0.9205049276351929, 0.0, -0.39073100686073303))
No need to normalize since the rotated unit vector will maintain its unit length.
Testing result with simple trig
Notice that rotating around Y axis (looking down the axis) rotates clockwise and moves into negative quadrant. Negate either angle or axis
((0, -1, 0)) when constructing rotation matrix to screw the other way.
Angle between x axis and v
Note can get a signed angle using 2D vectors. eg only the XZ components
To make the vector length
d multiply it by the scalar
v *= d
Make a line.
To make an edge from origin to v, it would have vert coordinates
verts = (
(0, 0, 0),
And edges (indexing verts)
edges = (
which can be fed into
bpy.types.Mesh.from_pydata(verts, edges, faces) Eg make a new single edge mesh named "Line"
>>> me = D.meshes.new("Line")
>>> me.from_pydata(verts, edges, )