niku 5.8

本文通过使用Python和NumPy库解决三维空间中角度θ1、θ2、θ3的计算问题,特别是针对θ2计算结果与预期不符的情况进行详细分析,并通过图形展示计算结果。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 

得到的图theta2和答案不一样,不知道为什么,需要再检查!!!!!

"""niku 习题5.8"""
""" 乘除法要用数组  将列表转换为数组"""
import numpy as np
import matplotlib.pyplot as plt
import math  
plt.figure(figsize=(8,4))
""" 求theta1""" 
t =  np.arange(1,12,1)#生成一个数组,不是列表
px = list(np.array([3]*11))
py = list(np.arange(5,-6,-1))
pz = list(np.array([5]*11))
theta1=[0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.]
theta2=[0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.]
theta3=[0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.]
for s in range(0,11):
    a =math.atan2(px[s],py[s])
    theta1[s] = a
#print(theta1) 
  
"""求theta3""" 
for s in range(0,11):
    f = math.acos(((py[s]/math.cos(theta1[s]))**2+(pz[s]-8)**2-162)/162 )    
    theta3[s] = f
#print(theta3)
    
"""求theta2"""
for s in range(0,11):
    q = math.cos(theta1[s])*(pz[s]-8)*(1+math.cos(theta3[s]))+py[s]*math.sin(theta3[s])
    e = 18*(1+math.cos(theta3[s]))*math.cos(theta1[s])
    t = math.acos(q/e)
    theta2[s] = t*180/3.1415
    
for s in range(0,11):
    t = theta1[s]
    theta1[s] = t*180/3.1415

for s in range(0,11):
    t = theta3[s]
    theta3[s] = t*180/3.1415

"""开始画图 画图的时候要用数组"""
t = np.arange(1,12,1)
theta1 = np.array(theta1)
theta2 = np.array(theta2)
theta3 = np.array(theta3)
plt.plot(t,theta1,label="$theta1$",color="red",linewidth=2)
plt.plot(t,theta2,label="$theta2$",color="blue",linewidth=2)
plt.plot(t,theta3,label="$theta3$",color="green",linewidth=2)
plt.ylim(-20,180)
plt.xlim(-1,12)
plt.xlabel("point")
plt.ylabel("theta")
plt.legend(loc="upper left")
plt.grid(True)
plt.show()

  

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值