Plane to Plane Intersection

Hey guys,

i want to code a plane to plane intersection by selecting the two edges to set the extrusion/move direction and then with a Shortcut for example “i” execute the intersection.

Do you have any ideas on how to do that?

Pictures are here below


There’s a utility function that will return two vectors for the intersection:
https://docs.blender.org/api/current/mathutils.geometry.html#mathutils.geometry.intersect_plane_plane

Hey testure, I am glad for your tipps :slight_smile: I should take a look deeper in the blender documentation.

Thats my first attemp:

import bpy
import mathutils

edge1 = bpy.context.active_object

p1 = edge1.data.polygons[0]

n1 = edge1.matrix_world.inverted_safe().transposed().to_3x3() @ p1.normal

point1 = edge1.location

print("n1:",n1)
print("p1:",p1.normal)
print("point1:",point1)
print("")

###########################################################################

edge2 = bpy.context.active_object

p2 = edge2.data.polygons[1]

n2 = edge2.matrix_world.inverted_safe().transposed().to_3x3() @ p2.normal

point2 = edge2.location

print("n2:",n2)
print("p2:",p2.normal)
print("point2:",point2)

intersect = mathutils.geometry.intersect_plane_plane(point1, n1, point2, n2)

print("")
print("intersection:",intersect)

and the console gives me those values:

n1: <Vector (-0.1037, -0.3945, 0.9130)>
p1: <Vector (0.0000, -0.0937, 0.9956)>
point1: <Vector (-0.2700, -0.0915, 0.6899)>

n2: <Vector (0.0000, 0.5157, 0.8568)>
p2: <Vector (0.0967, 0.7519, 0.6521)>
point2: <Vector (-0.2700, -0.0915, 0.6899)>

intersection: (Vector((-0.05911330506205559, -0.11470327526330948, 0.7038570642471313)), Vector((-0.9918880462646484, 0.1089056134223938, -0.06555584818124771)))

Problem is, that I use bpy.context.active_object twice so i will get for point1 and point 2 the same values :confused:

would you store the first edge and then the second one with a Mouse-click event instead my syntax?

Simplest thing would be to select both objects in blender switch to edit mode and select both edges. Hope it helps. :slightly_smiling_face:

import bpy
import mathutils

def calc():
    s_objs=  bpy.context.selected_objects
    if len(s_objs) != 2: 
        return
    
    selectedEdges1 = [e for e in s_objs[0].data.edges if e.select]
    selectedEdges2 = [e for e in s_objs[1].data.edges if e.select]
    
    if len(selectedEdges1) <1 or len(selectedEdges2) <1:
        return
    
    edge_obj_1 = s_objs[0]

    p1 = edge_obj_1.data.polygons[0]

    n1 = edge_obj_1.matrix_world.inverted_safe().transposed().to_3x3() @ p1.normal

    point1 = edge_obj_1.location

    print("n1:",n1)
    print("p1:",p1.normal)
    print("point1:",point1)
    print("")

    ###########################################################################

    edge_obj_2 = s_objs[1]
    p2 = edge_obj_2.data.polygons[0]

    n2 = edge_obj_2.matrix_world.inverted_safe().transposed().to_3x3() @ p2.normal

    point2 = edge_obj_2.location

    print("n2:",n2)
    print("p2:",p2.normal)
    print("point2:",point2)

    intersect = mathutils.geometry.intersect_plane_plane(point1, n1, point2, n2)

    print("")
    print("intersection:",intersect)
    

calc()

Hey @Debuk

Thanks a lot that solved my Problem :-).

There is one thing i am concerned, and thats the result blender gives me for the intersection:

Output of the intersection is one Vector/Vertex in the Middle of the intersection and the second vertex/vector is at the beginning of the intersectio, but with wrong values for Z hmm.

i thought i get two values for the intersection (pictures below)


Well no, its not two points. The formula is about intersection of two infinite planes. If an intesection exists the result is an also infinite line, and that line is described by a point and directional vector.

ok I understood that, but the directional vector is not right, if you look to the upper point :confused:

No I guess its right. A directional vector is what it says, just a direction, its per definition originating from the world origin. So to better grasp it, think of a line from the world origin to that point , thats the DIRECTION of your cut.

ohh ok i know what you mean, so then i should add the Z-Value of the intersection Point to the Z-Value of the direction point to get “two points”.

next thing will be connecting those planes using the intersection by for example

bpy.ops.transform.edge_slide(value=0.333651, mirror=True, correct_uv=True)

I will try to figure it out :slight_smile:

Well no, that will be wrong for almost all plane orientations.

But to give you a start. That intersection result is a point and a directional vector.
We will call the point p and the direction d

If you want an arbitrary point along that intersection line you have to calculate it like this.

arbitrary_point_on_line = p + scalar * d
where scalar is an arbitrary float value of your choice, eg 5

So for different values put into the scalar you then get different points on your intersection line.

1 Like

you are math pro :smiley: thanks a lot:

ap = intersect[0] + 1 * intersect[1]

gives me the correct point :-)!

1 Like