javascript - I there a function to divide the values in one vector with values in another?
问题描述
I have two vectors, this.position and grid.dimensions. I know you can't divide vectors but I would like to do something like
let gridCell = createVector(this.position.x / grid.dimensions.x, this.position.y / grid.dimensions.y)
Is there some way to do this? I tried:
let gridCell = p5.Vector.div(this.position, grid.dimensions),
but this .div only accepts values.
解决方案
看起来参考中没有一个功能可以满足您的需求。我认为您最好的选择是提出自己的解决方案。
您的第一个代码片段对我来说很好。你可以把它放到一个函数中,这样你就不必用它弄乱你的代码,但这是一个小细节。
推荐阅读
- django - Django Rest Framework 基本身份验证与 Apache 2.4 基本身份验证 - 我的 API 请求在哪里进行身份验证?
- android - 可触摸不适用于位置:绝对
- vue.js - Vue-cli 全局更改对象值
- visual-studio-code - 如何在 Visual Studio Code 中使用 Flutter 的 Widget Inspector?
- ios - swift:守卫“让自我= ...”的快捷方式?
- node.js - 对于 angular 4 的现有项目,安装 npm 失败
- pdf - Datatable 将通用数据导出到表外
- javascript - PaperJS如何在组项目中找到离鼠标事件最近的项目
- swift4.2 - Swift 4.2.1 使用 Xcode 10.1 请求 JSON
- postgresql - 替换二维数组中的元素