Dividing a 'Shape' - Closed Solved

Before continue reading, take a look at the attached image first, as it may help alot in understanding the problem. I have this shape. It is a mesh, created by giving it an outline of vector3’s and triangulate them. That is the initial form.

Now I want to be able to divide it (or create the illusion of division) by drawing lines across it. As you can see in the image, I have the two lines AB and CD. These lines already divided the shape, but these are easy to do because they don’t touch other lines. The line MN is a different story.

But lets ignore the shape for a second, and focus only on the lines. How can I calculate if and/or where the line MN touches the lines AB or CD.

(My ultimate goal is to be able to divide the ‘shape’ at will, later on, add vertex control, both inside and on the edge of the shape, to be able to select the divisions, lines and verteces, and maybe even delete them.)

got some old java code around … ;D

    public String getLocation(Vector2 linie_a,Vector2 linie_b,Vector2 punkt)
    {
       
        String tmp_String = null;
       
        float dot_Product = (linie_b.x - linie_a.x) * (punkt.y - linie_a.y) - (linie_b.y - linie_a.y) * (punkt.x - linie_a.x);
       
        if(dot_Product  > 0) tmp_String = "right";
        if(dot_Product  < 0) tmp_String = "left";
        if(dot_Product == 0) tmp_String = "on line";
       
        float dif_Xa = punkt.x - linie_a.x;
        float dif_ya = punkt.y - linie_a.y;
               
        float dif_Xb = punkt.x - linie_b.x;
        float dif_Yb = punkt.y - linie_b.y;
       
        System.out.println("Der Winkel beträgt " +((Math.atan2(dif_Xa,dif_ya) + (Math.atan2(dif_Xb,dif_Yb))) /2 / Math.PI *180)+" °");
        System.out.println(tmp_String);
       
        return tmp_String;
    }

I don’t think this will work. It only takes in 3 vectors, (I imagined something with at least 4) and it returns a string, not the intercepting point.
Maybe I didn’t explain correctly

you dont need all the code its about the dot product with this you can check if a point is on the right or left side of a line if it is 0 the point is on the line so if your 2 vectors of a line return right and left you cross the line

I’m not following you. My math isn’t that good.
I’ve checked Unity’s dot product and still don’t get it. (Unity - Scripting API: Vector3.Dot)
Can you write some code?

using UnityEngine;
using System.Collections;

public class Dot : MonoBehaviour
{
    private class Line
    {
        public Vector3 point_a ;
        public Vector3 point_b ;
        public Line(Vector3 a, Vector3 b)
        {
            this.point_a = new Vector3 (a.x, a.y, a.z);
            this.point_b = new Vector3 (b.x, b.y, b.z);
        }

    }
    Line line_a = new Line(new Vector3(5,0,0),new Vector3(5,10,0));// the midle line
    Line line_b = new Line(new Vector3(0,5,0),new Vector3(10,0,0));// the line will cross the mid
    Line line_c = new Line(new Vector3(0,5,0),new Vector3(4,0,0));// this line is to short



    void Start ()
    {
        float dot_product;

        //line_a & line_b

        // we compare line_a with point_a of line_b
        dot_product = (line_a.point_b.x - line_a.point_a.x) * (line_b.point_a.y - line_a.point_a.y) - (line_a.point_b.y - line_a.point_a.y) * (line_b.point_a.x - line_a.point_a.x);
        ReturnState (dot_product);// it retun right

        // we compare line_a with point_b of line_b
        dot_product = (line_a.point_b.x - line_a.point_a.x) * (line_b.point_b.y - line_a.point_a.y) - (line_a.point_b.y - line_a.point_a.y) * (line_b.point_b.x - line_a.point_a.x);
        ReturnState (dot_product);// it retun left
        // now we got one point left and one right so the line_b is crossing line_a


        //line_a & line_c
      
        // we compare line_a with point_a of line_c
        dot_product = (line_a.point_b.x - line_a.point_a.x) * (line_c.point_a.y - line_a.point_a.y) - (line_a.point_b.y - line_a.point_a.y) * (line_c.point_a.x - line_a.point_a.x);
        ReturnState (dot_product);// it retun right
      
        // we compare line_a with point_b of line_c
        dot_product = (line_a.point_b.x - line_a.point_a.x) * (line_c.point_b.y - line_a.point_a.y) - (line_a.point_b.y - line_a.point_a.y) * (line_c.point_b.x - line_a.point_a.x);
        ReturnState (dot_product);// it retun right
        // now we got two points on the right side so the lines dont cross


    }

    private void ReturnState(float dot)
    {
        if(dot  > 0)Debug.Log ("right");
        if(dot  < 0)Debug.Log ("left");
        //if(dot_Product == 0) tmp_String = "on line";
    }

The strange part for me is that you only take 1 vector3 for each line. Don’t you need 2? One for the beguining and one for the end? And there is no return of the vector3 of the intercepting point (if there is any)

i always take 2 Vectors of one line and compare it to one vector of the second line when i do this two times i know if it cross the first line or not.

Where they cross ?
I dont know but if i get bored today i will take a look later…

And here 2 usefull links

found out how to do it
http://www.wyrmtale.com/blog/2013/115/2d-line-intersection-in-c