# How to judge and prevent the intersection of lines

Hello
can you give me some help to judge and prevent the intersection of lines.

What does your code look like?
It seems you have wrong coordinates for the vertices.

Take a look at these simple examples from the Collection of examples from discourse.threejs.org .

NumberingHelperExamples

Yeah, my coordinates for the vertices is wrong(https://discourse.threejs.org/t/non-simple-self-intersecting-polygon-troubles/8951), but i did it on purpose, because my idea is when draw lines and happen intersection, how to prevent mouse click this wrong coordinate of vertices(picture 1). Can you give me some Help? Thanks！

This is my code:
{
Plane2Entity.prototype.setGeometry = function (vertices) {

``````this.entity.clear();
let points = vertices.map(obj => new THREE.Vector2(obj.x, obj.z));
let shape = new THREE.Shape(points);
this._geometry = new THREE.ExtrudeGeometry(shape, { 'depth': 0.1, bevelEnabled: false});
//console.log(this._geometry);
this._geometry.rotateX(Math.PI / 2);
// edge
this._edgeGeo = new THREE.EdgesGeometry(this._geometry);
this._edge = new THREE.LineSegments(this._edgeGeo, this._lineMaterial);
// mesh
this._mesh = new THREE.Mesh(this._geometry, this._meshMaterial);
// points
this._points = new THREE.Points(this._geometry, this._pointMaterial);
``````

}
}

Yeah, my coodinate is wrong, but i did it on purpose, how can i prevent mouse click on this situasion happen (purpose make wrong coodinate), this picture effect is what i want, it can penvent line segment intersection.

My code shows that:

``````let points = vertices.map(obj => new THREE.Vector2(obj.x, obj.z));
let shape = new THREE.Shape(points);
this._geometry = new THREE.ExtrudeGeometry(shape, { 'depth': 0.1, bevelEnabled: false});
//console.log(this._geometry);
this._geometry.rotateX(Math.PI / 2);

// edge
this._edgeGeo = new THREE.EdgesGeometry(this._geometry);
this._edge = new THREE.LineSegments(this._edgeGeo, this._lineMaterial);
// mesh
this._mesh = new THREE.Mesh(this._geometry, this._meshMaterial);
// points
this._points = new THREE.Points(this._geometry, this._pointMaterial);
``````

I think my question can be translated into how to judge a line segment and a line segment intersection.

My question is solved.

code:
{
export function LineIntersectLine(lineA, lineB) {

``````const [[a0x, a0y], [a1x, a1y]] = lineA
const [[b0x, b0y], [b1x, b1y]] = lineB;

// Test for shared points
if (a0x === b0x && a0y === b0y) return true;
if (a1x === b1x && a1y === b1y) return true;

const denom = ((b1y - b0y) * (a1x - a0x)) - ((b1x - b0x) * (a1y - a0y));

if (denom === 0) return false;

const deltaY = a0y - b0y;
const deltaX = a0x - b0x;
const numer0 = ((b1x - b0x) * deltaY) - ((b1y - b0y) * deltaX);
const numer1 = ((a1x - a0x) * deltaY) - ((a1y - a0y) * deltaX);
const quotA = numer0 / denom;
const quotB = numer1 / denom;

return quotA > 0 && quotA < 1 && quotB > 0 && quotB < 1;
``````

}
}