Use Vectors.
The 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()
>>> v
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
>>> degrees(acos(v.x))
22.99998912203489
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.
>>> degrees(asin(v.z))
-22.999992429369787
Angle between x axis and v
>>> degrees(x_axis.angle(v))
22.999989256384694
Note can get a signed angle using 2D vectors. eg only the XZ components
>>> degrees(v.xz.angle_signed(x_axis.xz))
-22.999992671479276
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),
v,
)
And edges (indexing verts)
edges = (
(0, 1),
)
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, [])