def draw
background(240)
v0 = createVector(0, 0)
v1 = createVector(mouseX, mouseY)
drawArrow(v0, v1, 'black')
noStroke
text(format("vector length squared: %.2f", v1.magSq), 10, 45, 90, 55)
end
def drawArrow(base, vec, myColor)
push do
stroke(myColor)
strokeWeight(3)
fill(myColor)
translate(base.x, base.y)
line(0, 0, vec.x, vec.y)
rotate(vec.heading)
arrowSize = 7
translate(vec.mag - arrowSize, 0)
triangle(0, arrowSize / 2, 0, -arrowSize / 2, arrowSize, 0)
end
end
ベクトルの大きさ(長さ)の2乗の値を取得します。
なし
r : ベクトルの大きさ(長さ)の2乗の値
・「(x * x) + (y * y) + (z * z)」の値と等価です。