# Calculate 3D Vertices with Python

I have 2 vertices in 3d space (P1, P3)

I want to create a rectangle that is aligned along the viewrotation. The vertices P1, P3 are already aligned to the current viewrotation matrix. How can I calculate P2 and P4 so that I can create a rectangle?

Alright, now I got a good solution, I wrote a function to calculate the vertex3d from 3d like this, that takes the roation of the viewport into account:

def get_3d_vertex(context, vertex_2d):
region    = context.region
rv3d      = context.space_data.region_3d
view_rot  = rv3d.view_rotation
overlay3d = context.space_data.overlay

dir = get_view_direction(context) * -context.scene.draw_distance
vec = region_2d_to_location_3d(region, rv3d, vertex_2d, dir)


When the rectangle is created I use the 2d mouse points to calculate all points of the rect:

def create_rect(self, context):
rv3d      = context.space_data.region_3d
view_rot  = rv3d.view_rotation

self._vertices.clear()

self._vertices.append(self._vertex1)

# self._vertex1 and 3 are already in 3d space
vertex2 = (self._vertex1_2d[0], self._vertex3_2d[1])
vertex2 = get_3d_vertex(context, vertex2)

vertex4 = (self._vertex3_2d[0], self._vertex1_2d[1])
vertex4 = get_3d_vertex(context, vertex4)

self._vertices.extend([vertex2, self._vertex3, vertex4])