从距离和向量创建向量 [英] Create vector from distance and vector
本文介绍了从距离和向量创建向量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何从另一个向量和一个距离创建向量?
How can I create vector from another vector and a distance?
例如,使用 vector3d(1,1,2)
和距离12,创建另一个具有相同方向但长12个单位的矢量.
For example, with a vector3d(1,1,2)
and distance 12, create another vector that has the same direction but is longer by 12 units.
推荐答案
您要查找单位向量沿您想要的方向;在XNA中,这是由 Vector3.Normalize
给出的.然后,您可以标量乘以该单位矢量(根据定义,其长度为1)乘以最终距离.
You want to find the unit vector in the direction you want; in XNA this is given by Vector3.Normalize
. Then you can scalar multiply that unit vector (which has, by definition, length = 1) by the final distance.
例如:
var originalVector = new Vector3(1, 1, 2);
var finalLength = originalVector.Length + 12; // "longer by 12", this could be whatever you want
originalVector.Normalize(); // make it a unit vector
var finalVector = originalVector * finalLength;
这篇关于从距离和向量创建向量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文