向量方向 [英] Direction of a vector

查看:79
本文介绍了向量方向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有:

a=magic(9);

如何计算a中任意两个点之间的矢量方向和大小?例如,如果我定义vec = [a(1,1) a(2,2)],矢量的方向是否会定义为:vecdir = a(1,1) - a(2,2)?

How do I compute the direction and magnitude of vectors between any two points in a? For example if I define vec = [a(1,1) a(2,2)], would the direction of the vector be defined as: vecdir = a(1,1) - a(2,2)?

推荐答案

vec = [x y]
dist = sqrt(sum(vec.^2)) % i.e. sqrt(x^2 + y^2)
dir = atan(y/x) % i.e. atan(vec(2) / vec(1))

这篇关于向量方向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆