# modeling/src/maths/line3/fromPlanes.js

``````const vec3 = require('../vec3')
const { solve2Linear } = require('../utils')

const { EPS } = require('../constants')

const fromPointAndDirection = require('./fromPointAndDirection')

/**
* Create a line the intersection of the given planes.
*
* @param {line3} out - receiving line
* @param {plane} plane1 - first plane of reference
* @param {plane} plane2 - second plane of reference
* @returns {line3} out
* @alias module:modeling/maths/line3.fromPlanes
*/
const fromPlanes = (out, plane1, plane2) => {
let direction = vec3.cross(vec3.create(), plane1, plane2)
let length = vec3.length(direction)
if (length < EPS) {
throw new Error('parallel planes do not intersect')
}
length = (1.0 / length)
direction = vec3.scale(direction, direction, length)

const absx = Math.abs(direction)
const absy = Math.abs(direction)
const absz = Math.abs(direction)
let origin
let r
if ((absx >= absy) && (absx >= absz)) {
// find a point p for which x is zero
r = solve2Linear(plane1, plane1, plane2, plane2, plane1, plane2)
origin = vec3.fromValues(0, r, r)
} else if ((absy >= absx) && (absy >= absz)) {
// find a point p for which y is zero
r = solve2Linear(plane1, plane1, plane2, plane2, plane1, plane2)
origin = vec3.fromValues(r, 0, r)
} else {
// find a point p for which z is zero
r = solve2Linear(plane1, plane1, plane2, plane2, plane1, plane2)
origin = vec3.fromValues(r, r, 0)
}
return fromPointAndDirection(out, origin, direction)
}

module.exports = fromPlanes
``````