Python draw 2 vertices under specified angle EDIT! What I would like to achieve using python is,

Top view,

Z = 0.0 

Y = 0.0 

Vertex 0 = -1.0

vertex 1 = 1.0

Rotation on y axis (top view)

Point of rotation is either Vertex 0, mid-point or Vertex1

The angle is user specified and point of rotation also (just hard coded)

Line should remain same length when angle is adjusted

When the distance between the 2 vertices is adjusted (I.E. V0 = 0.5 and V1 = 1.5 the angle should remain the same)

In the screenshot I tried to make example

First line (example) is straight 0 degrees

Second line (example) is 45 degrees angle and V0 = -1.0 and V1 = 1

Third line (example) is also 45 degrees angle but v0 = -1 and V1 = 0.

I just want to draw 2 vertices including an edge (3 might also be good so the vertex in the middle can be used as point of rotation) and change the angle of the edge.

But when the distance between the 2 vertices becomes smaller or bigger the angle should remain the same.

Important is that the vertices always stays on the given X axis grid point.
Y axis needs to be recalculated to get the specified angle.



old post!!

I would like to ask some help regarding mathutils and vectors (edges)
At the moment I use this code to add 2 vertices (1 edge)
But I would like to be able to adjust the angle of this line in such a way that no matter the distance between the 2 vertices the angle will always be fixed. I.E. 10 degrees or whatever I input as user. 
I search this forum and internet but could not find any similar to my question

import bpy
import bmesh
import mathutils
from mathutils import Vector
from bpy.types import Operator
from bpy_extras.object_utils import AddObjectHelper, object_data_add
from bpy.props import FloatVectorProperty    

verts = [(1, 1, 0), (-1, 1, 0)]

mesh = bpy.data.meshes.new("mesh")  # add a new mesh
obj = bpy.data.objects.new("MyObject", mesh)  # add a new object using the mesh

scene = bpy.context.scene
bpy.context.collection.objects.link(obj)  # put the object into the scene (link)
bpy.context.view_layer.objects.active = obj   # set as the active object in the scene
bpy.context.active_object.select_set(state=True)  # select object

mesh = bpy.context.object.data
bm = bmesh.new()

for v in verts:
    bm.verts.new(v)  # add a new vert

bm.edges.new(bm.verts)




# make the bmesh the object's mesh
bm.to_mesh(mesh)  
bm.free()  # always do this when finished


The code below wil just draw a straight line from 1 to -1 (x axis)
I would like to get an angle like the picture



it is important that the vertices stay in same line (x axis) as seen on the screenshot. So rotating the line would not give the result I am after.

As seen in the screenshot V1 and V2 are still on the same grid line in the x direction
As far as i understand you seek for this. one way to do this is using the matrix.Rotation
the only thing i dont know and maybe @batFINGER or @Robin Betts can help in this is to extend the line to the asked X axis. As far as i get it @cexoso wants to "constrain" the vertices on the X axis. with other words the vertices are free to move on the Y axis and are fixed on the X axis respecting the given angle.

@batFINGER or @Robin Betts
May i ask you to edit this code so that the line will be extended on both sides to the X axis. I'll try to explain using an square. Screenshot is below the code.

Please note that in this example the outside vextors are drawn on -1.0 and 1.0 X axis
I added a third vector but it might not be needed. 

import bpy
import bmesh
import mathutils
from mathutils import Vector
from bpy.types import Operator
from bpy_extras.object_utils import AddObjectHelper, object_data_add
from bpy.props import FloatVectorProperty    
from mathutils import Matrix
from math import asin, pi, degrees, radians


angle = 10
mesh = bpy.data.meshes.new("mesh")  # add a new mesh
obj = bpy.data.objects.new("MyObject", mesh)  # add a new object using the mesh

scene = bpy.context.scene
bpy.context.collection.objects.link(obj)  # put the object into the scene (link)
bpy.context.view_layer.objects.active = obj   # set as the active object in the scene
bpy.context.active_object.select_set(state=True)  # select object

mesh = bpy.context.object.data
bm = bmesh.new()
test = [] 

V3 = bm.verts.new((1, 0, 0))
V2 = bm.verts.new((0, 0, 0))
V1 = bm.verts.new((-1, 0, 0))

bm.edges.new((V1, V2))
bm.edges.new((V2, V3))

bmesh.ops.rotate(   
    bm, verts=bm.verts, matrix=Matrix.Rotation(pi * angle / 180, 3, 'Z')) 

bm.to_mesh(mesh)  
bm.free()  # always do this when finished


Text continues below screenshot



Note 1 
On any given angle the edge should connect to the square
I dont know how to do this tbh. Im still learning lOL 

Hope my answer contributes to this question