L1=3;L2=3*(2^0.5);L3=3;
gamma=pi/4;
P1=5;P2=5;P3=3;
X1=5;Y1=0;
X2=0;Y2=6;
syms theta A2 B2 A3 B3 N1 N2 D f;
A2=L3*cos(theta)-X1;
B2=L3*sin(theta);
A3=L2*(cos(theta)*cos(gamma)-sin(theta)*sin(gamma))-X2;
B3=L2*(cos(theta)*sin(gamma)+sin(theta)*cos(gamma))-Y2;
N1=(B3*(P2^2-P1^2-A2^2-B2^2)-B2*(P3^2-P1^2-A3^2-B3^2));
N2=(-A3*(P2^2-P1^2-A2^2-B2^2)+A2*(P3^2-P1^2-A3^2-B3^2));
D=2*(A2*B3-B2*A3);
% 解方程
f=(N1^2+N2^2-(P1^2)*D^2);
% theta=vpasolve(f,theta,[-pi,pi]);
% theta1=double(theta);
% theta2=double(theta);
% 绘制f(theta)的函数图像
figure(1)
Q=-pi:0.0001:pi;
f=((L2.*(cos(Q).*sin(gamma)+sin(Q).*cos(gamma))-Y2).*(P2.^2-P1.^2-(L3.*cos(Q)-X1).^2-(L3.*sin(Q)).^2)-(L3.*sin(Q)).*(P3.^2-P1.^2-(L2.*(cos(Q).*cos(gamma)-sin(Q).*sin(gamma))-X2).^2-(L2.*(cos(Q).*sin(gamma)+sin(Q).*cos(gamma))-Y2).^2)).^2+(-(L2.*(cos(Q).*cos(gamma)-sin(Q).*sin(gamma))-X2).*(P2.^2-P1.^2-(L3.*cos(Q)-X1).^2-(L3.*sin(Q)).^2)+(L3.*cos(Q)-X1).*(P3.^2-P1.^2-(L2.*(cos(Q).*cos(gamma)-sin(Q).*sin(gamma))-X2).^2-(L2.*(cos(Q).*sin(gamma)+sin(Q).*cos(gamma))-Y2).^2)).^2-P1.^2.*(2.*((L3.*cos(Q)-X1).*(L2.*(cos(Q).*sin(gamma)+sin(Q).*cos(gamma))-Y2)-(L3.*sin(Q)).*(L2.*(cos(Q).*cos(gamma)-sin(Q).*sin(gamma))-X2))).^2;
plot(Q,f);
plot(Q,f,'Linewidth',2);
grid on