# ray-sphere-intersection
[![stable](http://badges.github.io/stability-badges/dist/stable.svg)](http://github.com/badges/stability-badges)
Test whether a ray intersects with a sphere.
```js
var intersect = require('ray-sphere-intersection')
var origin = [0, 0, 4],
direction = [0, 0, -1],
center = [0, 0, 0],
radius = 1
var hit = intersect([], origin, direction, center, radius)
if (hit) {
console.log(hit) // [0, 0, 1]
}
```
Adapted from [LibGDX](https://github.com/libgdx/libgdx/blob/9eba80c6694160c743e43d4c3a5d60a5bad06f30/gdx/src/com/badlogic/gdx/math/Intersector.java). PRs for optimizations/etc welcome.
## Usage
[![NPM](https://nodei.co/npm/ray-sphere-intersection.png)](https://www.npmjs.com/package/ray-sphere-intersection)
#### `out = intersect(out, origin, direction, center, radius)`
Determines if the 3D ray `(origin, direction)` intersects with the 3D sphere `(center, radius)`.
**Note:** `direction` must be normalized before calling this method
If no intersection occurs, returns `null`. Otherwise, the intersection point is stored in `out` and then returned.
## License
MIT, see [LICENSE.md](http://github.com/mattdesl/ray-sphere-intersection/blob/master/LICENSE.md) for details.
没有合适的资源?快使用搜索试试~ 我知道了~
ray-sphere-intersection:测试射线是否与球体相交
共7个文件
md:2个
js:2个
gitignore:1个
需积分: 47 5 下载量 40 浏览量
2021-05-02
12:20:16
上传
评论
收藏 4KB ZIP 举报
温馨提示
射线球相交 测试射线是否与球体相交。 var intersect = require ( 'ray-sphere-intersection' ) var origin = [ 0 , 0 , 4 ] , direction = [ 0 , 0 , - 1 ] , center = [ 0 , 0 , 0 ] , radius = 1 var hit = intersect ( [ ] , origin , direction , center , radius ) if ( hit ) { console . log ( hit ) // [0, 0, 1] } 改编自 。 PR的优化/等欢迎。 用法 out = intersect(out, origin, direction, center, radius) 确定3D射线(origin, dir
资源详情
资源评论
资源推荐
收起资源包目录
ray-sphere-intersection-master.zip (7个子文件)
ray-sphere-intersection-master
test.js 709B
.npmignore 96B
LICENSE.md 1KB
README.md 1KB
.gitignore 56B
index.js 726B
package.json 945B
共 7 条
- 1
愍蟊朙
- 粉丝: 21
- 资源: 4709
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0