# Camera frustum calculate Visible Point Of line

**URL:** <https://discourse.threejs.org/t/camera-frustum-calculate-visible-point-of-line/7770>\
**Category:** Questions\
**Tags:** math\
**Created:** [May 28, 2019, 2:24am UTC](https://discourse.threejs.org/t/camera-frustum-calculate-visible-point-of-line/7770 "2019-05-28T02:24:00Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![xjindf](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/xjindf/32/24657_2.png) [@xjindf](https://discourse.threejs.org/u/xjindf)\
**Post date:** [May 28, 2019, 2:24am UTC](https://discourse.threejs.org/t/camera-frustum-calculate-visible-point-of-line/7770/1 "2019-05-28T02:24:00Z")

</div>

I check if any of the planes of the frustum intersects with any of the lines I have in the scene:

```
    var line, tmpArr = [];
    function initDatas() {
        var geometry = new THREE.Geometry();
        geometry.vertices.push(
            new THREE.Vector3(0, 0, 0),
            new THREE.Vector3(0, 0, 50)
        );

        var material = new THREE.LineBasicMaterial({
            color: 0xffff00
        });
        line = new THREE.Line(geometry, material);
        line.frustumCulled = false;
        scene.add(line);
    }

       function onOrbitControlsEnd() {
        var frustum = new THREE.Frustum();
        frustum.setFromMatrix(new THREE.Matrix4().multiplyMatrices(camera.projectionMatrix, camera.matrixWorldInverse));

        var vStart, vEnd;
        var line3 = new THREE.Line3(), interP = new THREE.Vector3();
        var resultArr = [];
        for (var i = 0, len = line.geometry.vertices.length; i < len - 1; i++) {
            vStart = line.geometry.vertices[i];
            vEnd = line.geometry.vertices[i + 1];

            line3.set(vStart, vEnd);
            
            for (var j = 0; j < 6 ; j++) {
                var plane = frustum.planes[j];
                var intersect = plane.intersectLine(line3, interP);
                if (intersect && frustum.containsPoint(intersect)) {
                    resultArr.push({ intersect: intersect.clone() });
                }
            }
        }
        if (tmpArr.length > 0) {
            var len = tmpArr.length;
            while (len--) {
                scene.remove(tmpArr[len]);
            }
            tmpArr = [];
        }
        if (resultArr.length > 0) {
            for (var k = 0, kl = resultArr.length; k < kl; k++) {
                var mesh = new THREE.Mesh(new THREE.BoxBufferGeometry(1, 1, 1), new THREE.MeshBasicMaterial({ color: 0xff0000 }));
                mesh.position.copy(resultArr[k].intersect);
                mesh.frustumCulled = false;
                scene.add(mesh);
                tmpArr.push(mesh);
            }
        }
    }

```

I need to find the intersection of the cone and line segment in the visible range, as shown in the figure below, but the result is always beyond my expectation. I don’t know where the problem is. Please help me. Thank you very much.

 ![image](https://canada1.discourse-cdn.com/flex035/uploads/threejs/original/2X/1/115634e104cc44ae67230af04333129505102e84.png)

---

<div class="post-metadata">

**Author:** ![xjindf](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/xjindf/32/24657_2.png) [@xjindf](https://discourse.threejs.org/u/xjindf)\
**Post date:** [May 28, 2019, 3:38am UTC](https://discourse.threejs.org/t/camera-frustum-calculate-visible-point-of-line/7770/2 "2019-05-28T03:38:25Z")

</div>

When I call frustum. containsPoint method to determine whether the calculated intersection is within the field of vision, it seems that there is a problem in judging when the camera rotates to a certain angle. The specific debugging parameters are as follows:

 ![image](https://canada1.discourse-cdn.com/flex035/uploads/threejs/original/2X/d/d8cdea987802a35d3716d49fcc981c5ef125df6c.png)

This is the JSON data at the intersection point：  
{x: 0, y: 0, z: 10.247075764313756}

This is frustum’s JSON data：  
“{“planes”:[{“normal”:{“x”:-0.5636868038602206,“y”:-0.32766368167746085,“z”:0.7582174482715501},“constant”:1.7662915181826233},{“normal”:{“x”:-0.42846535657501705,“y”:-0.32766368167746085,“z”:-0.8420534127504116},“constant”:8.62858511805243},{“normal”:{“x”:-0.8246469760410625,“y”:0.5613392859326407,“z”:-0.06968192717601998},“constant”:3.3739057814523896},{“normal”:{“x”:0.18759615784538242,“y”:-0.9821183253373745,“z”:0.015851706474737833},“constant”:3.3005388553982007},{“normal”:{“x”:0.8323470057975492,“y”:0.5497743092841535,“z”:0.07033257275961624},“constant”:9991.279417771093},{“normal”:{“x”:-0.8323470057986695,“y”:-0.5497743092824827,“z”:-0.07033257275941693},“constant”:8.620582173626742}]}”
