首页 > 解决方案 > 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.

标签: javascriptp5.js

解决方案


看起来参考中没有一个功能可以满足您的需求。我认为您最好的选择是提出自己的解决方案。

您的第一个代码片段对我来说很好。你可以把它放到一个函数中,这样你就不必用它弄乱你的代码,但这是一个小细节。


推荐阅读