Project an edge until it intersects another edge and create a vertex on that edge

Note, a reference image is attached illustrating the steps, below:

We are working with a single Editable_Poly object. We have two edges on this poly that are not parallel, do not currently intersect, and _are_ co-planar, but the plane on which they are co-planar is not necessarily parallel to X, Y, or Z planes in any coordinate system (i.e., just some random plane, so let's not make any assumptions here):

Given vertices #1 and #2, we have edge A: #1 -> #2
Given vertices #3 and #4, we have edge B: #3 -> #4

As previously stated, edges A and B do not intersect. Imagine, we want to create a new edge which would be a logical extension of edge A, starting from vertex #1, in the direction of vertex #2, until it comes into contact with edge B. It would split polygon P into P1 and P2 (see attached image).

Let's call this new point, (p5), at which point we would like to place a vertex going forward. So, we have so far:

Edge A: #1 -> #2
Edge B: #3 -> #4
Future Edge C: #2 -> (p5) (we're in the process of creating this edge at this point, but we don't have a vertex at p5 to be able to create it)
Future split of polygon P into P1 and P2

We want to place a new vertex on edge B, called vertex #5, at the point (p5) (i.e., splitting edge B into edges B1 and B2 that are co-linear and connect at p5), after we calculate point p5's coordinates, so that Edge B gets split into edges B1 and B2 and polygon P gets split into P1 and P2 (once again, please see attached image):

Edge B1: #3 -> #5
Edge B2: #5 -> #4

Cross-check time, we want to make sure that:

Vertices #1, #2, and the newly created vertex #5 are co-linear. In other words, if we were to extend edge A from vertex #2, in the direction of vertex #5, it would eventually touch vertex #5.

Once all of the above is done, it would not be too difficult to create a cut from vertex #2 to vertex #5, connecting edges A, B1, and B2, at vertex #5, via a newly cut edge, which we will call Edge C. We would then have:

Edge A: From vertex #1 to vertex #2
Edge B1: From vertex #3 to vertex #5
Edge B2: From vertex #5 to vertex #4
Edge C: From vertex #2 to vertex #5
Polygons P1 and P2

A summary of the process:

We started with two edges A and B. We wanted to create a new edge that connects them, C, which is co-linear with edge A. In creating edge C, we wound up splitting edge B into edges B1 and B2, which are co-linear with respect to each other. The newly created edge C is co-linear with edge A.

Thanks for any ideas on how to script this, especially the determination of the coordinates of point p5.

AttachmentSize
cut.png27.67 KB

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
jahman's picture

.

Hi, Michael.
I guess if the segments are coplanar then it is enough to find line-line intersection to get the #5 point? And then you can split the edge in two according to the ratio
(distance #4 #5) / (distance #4 #3)

fn lineLineIntersect pA pB pC pD =
(
	local a=pB-pA
	local b=pD-pC
	local c=pC-pA
	local cross1 = cross a b
	local cross2 = cross c b
	pA + ( a*( (dot cross2 cross1)/((length cross1)^2) ) )
)
mikegold10's picture

The problem is that the line

The problem is that the line segments don't intersect and I don't know how much to extend one of them to make them intersect. That's part of the problem! If I knew the amount of extension necessary, I could easily calculate the intersection point.

jahman's picture

.

But isn't it the other way around?
First you get the intersection point between two lines (not segments) and only if it exists you need to check if this intersection point belongs to segment and the rest is trivial

btw what result do you expect if these two segments aren't coplanar?

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.