# EdgesGeoemtry thresholdAngle Inverse Result

**URL:** <https://discourse.threejs.org/t/edgesgeoemtry-thresholdangle-inverse-result/13782>\
**Category:** Questions\
**Tags:** geometry\
**Created:** [March 24, 2020, 5:15pm UTC](https://discourse.threejs.org/t/edgesgeoemtry-thresholdangle-inverse-result/13782 "2020-03-24T17:15:01Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![doczoidberg](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/doczoidberg/32/9977_2.png) [@doczoidberg](https://discourse.threejs.org/u/doczoidberg)\
**Post date:** [March 24, 2020, 5:15pm UTC](https://discourse.threejs.org/t/edgesgeoemtry-thresholdangle-inverse-result/13782/1 "2020-03-24T17:15:01Z")

</div>

I use  
`var egeometry = new THREE.EdgesGeometry(meshResult.geometry);`  
to get the edges of wall segements. With second parameter `thresholdAngle` 92 I get the exact opposite what I want. I get then the edges which are on a plane.But I need to remove these edges and show the now removed edges.

 ![edgesnoparam](https://canada1.discourse-cdn.com/flex035/uploads/threejs/original/2X/3/3fc3c82cbb3db70dd3e88287ec79ee18b13840d7.png)

 ![edges92](https://canada1.discourse-cdn.com/flex035/uploads/threejs/original/2X/b/be5fce8b29e7d560517aa18dfd19bd8be5d61079.png)

---

<div class="post-metadata">

**Author:** ![doczoidberg](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/doczoidberg/32/9977_2.png) [@doczoidberg](https://discourse.threejs.org/u/doczoidberg)\
**Post date:** [March 24, 2020, 8:12pm UTC](https://discourse.threejs.org/t/edgesgeoemtry-thresholdangle-inverse-result/13782/2 "2020-03-24T20:12:08Z")

</div>

I modified the EdgesGeoemtry code for a undefined check.

// generate vertices

```
for (key in edges) {

  var e = edges[key];

  // an edge is only rendered if the angle (in degrees) between the face normals of the adjoining faces exceeds this value. default = 1 degree.

  if (

    e.face2 === undefined ||

    (faces[e.face1].normal.dot(faces[e.face2].normal) <= thresholdDot)) {//} && faces[e.face1].normal.dot(faces[e.face2].normal) >= thresholdDot2)) {

    if (e.face2 !== undefined) {

      console.log('dot', e); // faces[e.face1].normal.dot(faces[e.face2].normal));

      var vertex = sourceVertices[e.index1];

      vertices.push(vertex.x, vertex.y, vertex.z);

      vertex = sourceVertices[e.index2];

      vertices.push(vertex.x, vertex.y, vertex.z);

    }

  }

}
```

---

<div class="post-metadata">

**Author:** ![user123](https://avatars.discourse-cdn.com/v4/letter/u/ed655f/32.png) [@user123](https://discourse.threejs.org/u/user123)\
**Post date:** [March 24, 2020, 8:40pm UTC](https://discourse.threejs.org/t/edgesgeoemtry-thresholdangle-inverse-result/13782/3 "2020-03-24T20:40:28Z")

</div>

So this looks interesting, as i have often noticed that angles above 90 don’t give me what I would expect (showing when they shouldn’t)

however I am very hesitant of changing a bit of the code in the core (e.g. not an example) as I use the min file.

Any suggestions on implementing this fix “externally” (e.g. in my own code)

---

<div class="post-metadata">

**Author:** ![doczoidberg](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/doczoidberg/32/9977_2.png) [@doczoidberg](https://discourse.threejs.org/u/doczoidberg)\
**Post date:** [March 24, 2020, 9:12pm UTC](https://discourse.threejs.org/t/edgesgeoemtry-thresholdangle-inverse-result/13782/4 "2020-03-24T21:12:56Z")

</div>

I’ve rewritten the new EdgeGeometry function:

private EdgesGeometry(geometry) {

```
// BufferGeometry.call(this);

// this.type = 'EdgesGeometry';

// this.parameters = {

// thresholdAngle: thresholdAngle

// };

var thresholdAngle = 1; // (thresholdAngle !== undefined) ? thresholdAngle : 1;

// buffer

var vertices = [];

// helper variables

var thresholdDot = Math.cos(MathUtils.DEG2RAD * 1);

var thresholdDot2 = Math.cos(MathUtils.DEG2RAD * 1111);

var edge = [0, 0], edges = {}, edge1, edge2;

var key, keys = ['a', 'b', 'c'];

// prepare source geometry

var geometry2;

if (geometry.isBufferGeometry) {

  geometry2 = new THREE.Geometry();

  geometry2.fromBufferGeometry(geometry);

} else {

  geometry2 = geometry.clone();

}

geometry2.mergeVertices();

geometry2.computeFaceNormals();

var sourceVertices = geometry2.vertices;

var faces = geometry2.faces;

// now create a data structure where each entry represents an edge with its adjoining faces

for (var i = 0, l = faces.length; i < l; i++) {

  var face = faces[i];

  for (var j = 0; j < 3; j++) {

    edge1 = face[keys[j]];

    edge2 = face[keys[(j + 1) % 3]];

    edge[0] = Math.min(edge1, edge2);

    edge[1] = Math.max(edge1, edge2);

    key = edge[0] + ',' + edge[1];

    if (edges[key] === undefined) {

      edges[key] = { index1: edge[0], index2: edge[1], face1: i, face2: undefined };

    } else {

      edges[key].face2 = i;

    }

  }

}

// generate vertices

for (key in edges) {

  var e = edges[key];

  // an edge is only rendered if the angle (in degrees) between the face normals of the adjoining faces exceeds this value. default = 1 degree.

  if (

    e.face2 === undefined ||

    (faces[e.face1].normal.dot(faces[e.face2].normal) <= thresholdDot)) {//} && faces[e.face1].normal.dot(faces[e.face2].normal) >= thresholdDot2)) {

    if (e.face2 !== undefined) {

      console.log('dot', e); // faces[e.face1].normal.dot(faces[e.face2].normal));

      var vertex = sourceVertices[e.index1];

      vertices.push(vertex.x, vertex.y, vertex.z);

      vertex = sourceVertices[e.index2];

      vertices.push(vertex.x, vertex.y, vertex.z);

    }

  }

}

var g = new THREE.BufferGeometry();

g.type = "EdgesGeometry";

// build geometry

var b = new Float32BufferAttribute(vertices, 3);

g.setAttribute('position', b);

return g;

```

}
