var Vector = function(x, y) {//点的x,y坐标
this.x = x;
this.y = y;
};
Vector.prototype = {
getMagnitude: function () {
return Math.sqrt(Math.pow(this.x, 2) +
Math.pow(this.y, 2));
},
add: function (vector) {
var v = new Vector();
v.x = this.x + vector.x;
v.y = this.y + vector.y;
return v;
},
subtract: function (vector) {
var v = new Vector();
v.x = this.x - vector.x;
v.y = this.y - vector.y;
return v;
},
dotProduct: function (vector) {
return this.x * vector.x +
this.y * vector.y;
},
edge: function (vector) {
return this.subtract(vector);
},
perpendicular: function () {//得到与之垂直的向量
var v = new Vector();
v.x = this.y;
v.y = 0-this.x;
return v;
},
normalize: function () {
var v = new Vector(),
m = this.getMagnitude();
v.x = this.x / m;
v.y = this.y / m;
return v;
},
normal: function () {//得到与之垂直的单位向量,主要用来指示方向
var p = this.perpendicular();
return p.normalize();
}
};
Vector-向量对象57
原创
©著作权归作者所有:来自51CTO博客作者生而为人我很遗憾的原创作品,请联系作者获取转载授权,否则将追究法律责任
上一篇:Shape.js-图形综合56
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
向量(vector)
向量(vector)
标量 段长度 记法 -
python中利用turtle库绘制一条直线
Death is so final, whereas life is so full of possibilities。死了可什么都没了,而活着就有无限的可能。《权力的游戏》往日回顾:来学Python啦,用Python详细讲解温度转换器这次咱们开头先详细了解一下Python及其它编程语言,关于编程语言有很多,据说超过六百多种。可真正常用的也就那么几十种,毕竟谁更好用谁就更强大嘛,可谓说在编程
python turtle绕原点旋转 Python&按键精灵自动化 python画图大小 Python ci