已知坐标求角度
【摘要】
import torchimport numpy as np data = [-0.9999,-0.5, -0.1, 0.8,0.9]tensor = torch.FloatTensor(data) # 转换成32位浮点 tensor def getAngle(x, y): a = torch.atan2(y, x); ret = a *...
-
-
import torch
-
import numpy as np
-
-
data = [-0.9999,-0.5, -0.1, 0.8,0.9]
-
tensor = torch.FloatTensor(data) # 转换成32位浮点 tensor
-
-
-
def getAngle(x, y):
-
a = torch.atan2(y, x);
-
ret = a * 180 / np.pi #弧度转角度,方便调试
-
if (ret > 360):
-
ret -= 360;
-
-
if (ret < 0):
-
ret += 360;
-
return ret;
-
-
-
print(getAngle(torch.FloatTensor([-1]),torch.FloatTensor([1])))
批量求角度
-
import numpy as np
-
-
data = [-0.9999,-0.5, -0.1, 0.8,0.9]
-
tensor = torch.FloatTensor(data) # 转换成32位浮点 tensor
-
-
-
def getAngle(x, y):
-
ret = torch.atan2(y, x);
-
# ret = a * 180 / np.pi #弧度转角度,方便调试
-
-
ret[ret > 2*np.pi]=ret[ret > 2*np.pi]-2*np.pi
-
ret[ret < 0]=ret[ret < 0]+2*np.pi
-
-
ret=ret*180/np.pi
-
return ret;
-
-
-
x=torch.FloatTensor([1,1])
-
y=torch.FloatTensor([-1,1])
-
print(getAngle(y,x))
文章来源: blog.csdn.net,作者:网奇,版权归原作者所有,如需转载,请联系作者。
原文链接:blog.csdn.net/jacke121/article/details/104039572
【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)