为什么两圆交点的坐标x与y的表达式不对称呢?
FullSimplify@Solve[{(x-x1)^2+(y-y1)^2==r1^2,(x-x2)^2+(y-y2)^2==r2^2},{x,y}]假设两个圆相交,为什么圆的交点的方程不对称呢?
我现在需要找个公式,直接得出两个圆的交点,但是利用mathematica的出来的公式不是对称的
我觉得x与y的地位是相同的,为什么x表达式有两个根号,而y表达式只有一个根号呢? 从Solve返回的结果来看,它是先消去y,得到关于x的方程,然后再带回去求解的,然后在化简的时候,化简的不够彻底,所以看起来不对称,我们可以自定义一部分变换,这样就得到比较对称的结果了
eqn = {(x - x1)^2 + (y - y1)^2 == r1^2, (x - x2)^2 + (y - y2)^2 == r2^2};
trans = {Automatic, Factor, Collect[#, Sqrt] &, PowerExpand[#, y1 - y2] &};
sol = Simplify, TransformationFunctions -> trans]
改成FullSimplify效果更好一些,但算得也慢了,对结果进一步整理,可以写成下面的形式
\begin{array}{l}
\left\{x\to \frac{\text{x1}+\text{x2}}{2}+\frac{\left(\text{r2}^2-\text{r1}^2\right) (\text{x1}-\text{x2})-(\text{y1}-\text{y2}) \text{deta}}{2 d^2},y\to \frac{\text{y1}+\text{y2}}{2}+\frac{\left(\text{r2}^2-\text{r1}^2\right) (\text{y1}-\text{y2})+(\text{x1}-\text{x2}) \text{deta}}{2 d^2}\right\} \\
\left\{x\to \frac{\text{x1}+\text{x2}}{2}+\frac{\left(\text{r2}^2-\text{r1}^2\right) (\text{x1}-\text{x2})+(\text{y1}-\text{y2}) \text{deta}}{2 d^2},y\to \frac{\text{y1}+\text{y2}}{2}+\frac{\left(\text{r2}^2-\text{r1}^2\right) (\text{y1}-\text{y2})-(\text{x1}-\text{x2}) \text{deta}}{2 d^2}\right\} \\
\end{array}
其中
$d=\sqrt{(\text{x1}-\text{x2})^2+(\text{y1}-\text{y2})^2}$
$\text{deta}=\sqrt{\left(d^2-(\text{r1}-\text{r2})^2\right) \left((\text{r1}+\text{r2})^2-d^2\right)}$
补充内容 (2018-7-17 20:07):
代码里改成Collect[#, Sqrt, FullSimplify] &效果更好 楼上的给赞.
我第一感觉应该祭出Reduce.试了下,但是凭着肉眼,是不能立马判定是否是对称的.得有一定的半手工过程来确认,放弃之.:L
可以试着手工来
\(\begin{cases}(x-x_1)^2+(y-y_1)^2=r_1^2 \\ (x-x_2)^2+(y-y_2)^2=r_2^2\end{cases}\)
记\(\bar{x}=\frac{x_1+x_2}2,\bar{y}=\frac{y_1+y_2}2, d^2=(x_1-x_2)^2+(y_1-y_2)^2\)
上面两式相减除以2,可以得出\((x_2-x_1)(x-\bar{x})+(y_2-y_1)(y-\bar{y})=\frac{r_1^2-r_2^2}2\)
两式相加除以2,可以得出\((x^2-\bar{x})^2+(y^2-\bar{y})^2=\frac{d^2}4+\frac{r_1^2+r_2^2}2\)
记\(A=x_2-x_1,B=y_2-y_1,C=\frac{r_1^2-r_2^2}2,D=\frac{d^2}4+\frac{r_1^2+r_2^2}2,X=x-\bar{x},Y=y-\bar{y}\),其中\(B^2+C^2=d^2\)
于是有二元二次方程组
\(\begin{cases}AX+BY=C\\X^2+Y^2=D\end{cases}\)
解得$X={AC +- \sqrt{A^2C^2-(C^2-DB^2)d^2}}/{d^2}={AC +- B\sqrt{Dd^2-C^2}}/{d^2}$ chyanog 发表于 2018-6-5 11:10
从Solve返回的结果来看,它是先消去y,得到关于x的方程,然后再带回去求解的,然后在化简的时候,化简的不 ...
Clear["Global`*"];(*Clear all variables*)
(*下面六个无理数,不可能被加减乘除消化掉,所以先得出一个伪符号解*)
x1=EulerGamma;
y1=Catalan;
x2=Khinchin;
y2=Glaisher;
r1=Pi;
r2=E;
out=FullSimplify@Solve[{(x-x1)^2+(y-y1)^2==r1^2,(x-x2)^2+(y-y2)^2==r2^2},{x,y},Reals]
(*回代得到符号解*)
out/.{EulerGamma->x1,Catalan->y1,Khinchin->x2,Glaisher->y2,Pi->r1,E->r2}
应该能求得解的,为什么不能? mathematica 发表于 2018-7-25 09:31
应该能求得解的,为什么不能?
Clear["Global`*"];(*Clear all variables*)
(*下面六个无理数,不可能被加减乘除消化掉,所以先得出一个伪符号解*)
x1=EulerGamma;
y1=Catalan;
x2=Khinchin;
y2=Glaisher;
r1=Pi;
r2=E;
out=FullSimplify@Solve[{(x-x1)^2+(y-y1)^2==r1^2,(x-x2)^2+(y-y2)^2==r2^2},{x,y}]
(*回代得到符号解*)
outxy={x,y}/.out
Replace
为什么就是替换不过来呢?
\[\left(
\begin{array}{cc}
\frac{1}{2} \left(\frac{(\gamma -K) (e-\pi ) (e+\pi )+(C-A) \sqrt{-\left((\gamma -K)^2+C^2-e^2+A^2-2 C A\right)^2-\pi ^4+2 \left((C-A)^2+e^2+(\gamma -K)^2\right) \pi ^2}}{(C-A)^2+(\gamma -K)^2}+K+\gamma \right) & \frac{1}{2} \left(\frac{(C-A) (e-\pi ) (e+\pi )+(-\gamma +K) \sqrt{-\left((\gamma -K)^2+C^2-e^2+A^2-2 C A\right)^2-\pi ^4+2 \left((C-A)^2+e^2+(\gamma -K)^2\right) \pi ^2}}{(C-A)^2+(\gamma -K)^2}+A+C\right) \\
\frac{1}{2} \left(\frac{(\gamma -K) (e-\pi ) (e+\pi )+(-C+A) \sqrt{-\left((\gamma -K)^2+C^2-e^2+A^2-2 C A\right)^2-\pi ^4+2 \left((C-A)^2+e^2+(\gamma -K)^2\right) \pi ^2}}{(C-A)^2+(\gamma -K)^2}+K+\gamma \right) & \frac{1}{2} \left(\frac{(C-A) (e-\pi ) (e+\pi )+(\gamma -K) \sqrt{-\left((\gamma -K)^2+C^2-e^2+A^2-2 C A\right)^2-\pi ^4+2 \left((C-A)^2+e^2+(\gamma -K)^2\right) \pi ^2}}{(C-A)^2+(\gamma -K)^2}+A+C\right) \\
\end{array}
\right)\] Clear["Global`*"];(*Clear all variables*)
(*下面六个无理数,不可能被加减乘除消化掉,所以先得出一个伪符号解*)
rule={x1,y1,x2,y2,r1,r2}->{EulerGamma,Catalan,Khinchin,Glaisher,\,E};
sol=Solve[{(x-x1)^2+(y-y1)^2==r1^2,(x-x2)^2+(y-y2)^2==r2^2}/.Thread,{x,y}]//FullSimplify;
(*回代得到符号解*)
sol/.Thread]
用你的代码之前,需要先清除变量一下
\[\left\{\left\{x\to \frac{1}{2} \left(\frac{(\text{y1}-\text{y2}) \sqrt{-\text{r1}^4+2 \text{r1}^2 \left(\text{r2}^2+(\text{x1}-\text{x2})^2+(\text{y1}-\text{y2})^2\right)-\left(-\text{r2}^2+(\text{x1}-\text{x2})^2+\text{y1}^2-2 \text{y1} \text{y2}+\text{y2}^2\right)^2}+(\text{r2}-\text{r1}) (\text{r1}+\text{r2}) (\text{x1}-\text{x2})}{(\text{x1}-\text{x2})^2+(\text{y1}-\text{y2})^2}+\text{x1}+\text{x2}\right),y\to \frac{1}{2} \left(\frac{(\text{x2}-\text{x1}) \sqrt{-\text{r1}^4+2 \text{r1}^2 \left(\text{r2}^2+(\text{x1}-\text{x2})^2+(\text{y1}-\text{y2})^2\right)-\left(-\text{r2}^2+(\text{x1}-\text{x2})^2+\text{y1}^2-2 \text{y1} \text{y2}+\text{y2}^2\right)^2}+(\text{r2}-\text{r1}) (\text{r1}+\text{r2}) (\text{y1}-\text{y2})}{(\text{x1}-\text{x2})^2+(\text{y1}-\text{y2})^2}+\text{y1}+\text{y2}\right)\right\},\left\{x\to \frac{1}{2} \left(\frac{(\text{y2}-\text{y1}) \sqrt{-\text{r1}^4+2 \text{r1}^2 \left(\text{r2}^2+(\text{x1}-\text{x2})^2+(\text{y1}-\text{y2})^2\right)-\left(-\text{r2}^2+(\text{x1}-\text{x2})^2+\text{y1}^2-2 \text{y1} \text{y2}+\text{y2}^2\right)^2}+(\text{r2}-\text{r1}) (\text{r1}+\text{r2}) (\text{x1}-\text{x2})}{(\text{x1}-\text{x2})^2+(\text{y1}-\text{y2})^2}+\text{x1}+\text{x2}\right),y\to \frac{1}{2} \left(\frac{(\text{x1}-\text{x2}) \sqrt{-\text{r1}^4+2 \text{r1}^2 \left(\text{r2}^2+(\text{x1}-\text{x2})^2+(\text{y1}-\text{y2})^2\right)-\left(-\text{r2}^2+(\text{x1}-\text{x2})^2+\text{y1}^2-2 \text{y1} \text{y2}+\text{y2}^2\right)^2}+(\text{r2}-\text{r1}) (\text{r1}+\text{r2}) (\text{y1}-\text{y2})}{(\text{x1}-\text{x2})^2+(\text{y1}-\text{y2})^2}+\text{y1}+\text{y2}\right)\right\}\right\}\] mathematica 发表于 2018-7-25 11:05
用你的代码之前,需要先清除变量一下
\[\left\{\left\{x\to \frac{1}{2} \left(\frac{(\text{y1}-\text ...
根号下的内容是
\[\left((\text{r1}+\text{r2})^2-(\text{x1}-\text{x2})^2-(\text{y1}-\text{y2})^2\right) \left(-(\text{r1}-\text{r2})^2+(\text{x1}-\text{x2})^2+(\text{y1}-\text{y2})^2\right)\] mathematica 发表于 2018-7-25 11:11
根号下的内容是
\[\left((\text{r1}+\text{r2})^2-(\text{x1}-\text{x2})^2-(\text{y1}-\text{y2})^2\ri ...
Clear["Global`*"];(*Clear all variables*)
(*下面六个无理数,不可能被加减乘除消化掉,所以先得出一个伪符号解*)
rule={x1,y1,x2,y2,r1,r2}->{EulerGamma,Catalan,Khinchin,Glaisher,\,E};
sol=Solve[{(x-x1)^2+(y-y1)^2==r1^2,(x-x2)^2+(y-y2)^2==r2^2}/.Thread,{x,y}]//FullSimplify;
(*回代得到符号解*)
sol=sol/.Thread]
out=sol/.{Sqrt[-r1^4+2*r1^2*(r2^2+(x1-x2)^2+(y1-y2)^2)-(-r2^2+(x1-x2)^2+y1^2-2*y1*y2+y2^2)^2]->delt,(x1-x2)^2+(y1-y2)^2->dd}//FullSimplify
FullSimplify@Factor[-r1^4+2*r1^2*(r2^2+(x1-x2)^2+(y1-y2)^2)-(-r2^2+(x1-x2)^2+y1^2-2*y1*y2+y2^2)^2]
得到两个结果
\[\left\{\left\{x\to \frac{1}{2} \left(\frac{\text{delt} (\text{y1}-\text{y2})+(\text{r2}-\text{r1}) (\text{r1}+\text{r2}) (\text{x1}-\text{x2})}{\text{dd}}+\text{x1}+\text{x2}\right),y\to \frac{1}{2} \left(\frac{\text{delt} (\text{x2}-\text{x1})+(\text{r2}-\text{r1}) (\text{r1}+\text{r2}) (\text{y1}-\text{y2})}{\text{dd}}+\text{y1}+\text{y2}\right)\right\},\left\{x\to \frac{1}{2} \left(\frac{\text{delt} (\text{y2}-\text{y1})+(\text{r2}-\text{r1}) (\text{r1}+\text{r2}) (\text{x1}-\text{x2})}{\text{dd}}+\text{x1}+\text{x2}\right),y\to \frac{1}{2} \left(\frac{\text{delt} (\text{x1}-\text{x2})+(\text{r2}-\text{r1}) (\text{r1}+\text{r2}) (\text{y1}-\text{y2})}{\text{dd}}+\text{y1}+\text{y2}\right)\right\}\right\}\]
\[-\left((\text{r1}-\text{r2})^2-(\text{x1}-\text{x2})^2-(\text{y1}-\text{y2})^2\right) \left((\text{r1}+\text{r2})^2-(\text{x1}-\text{x2})^2-(\text{y1}-\text{y2})^2\right)\] 本帖最后由 chyanog 于 2018-8-9 16:53 编辑
用含三角函数的式子表示也不错
$$\begin{array}{cc}
x\to x_1+r_1 \cos (\alpha +\beta ) & y\to y_1+r_1 \sin (\alpha +\beta ) \\
x\to x_1+r_1 \cos (\alpha -\beta ) & y\to y_1+r_1 \sin (\alpha -\beta ) \\
\end{array}$$
$d=\sqrt{\left(x_1-x_2\right)^2+\left(y_1-y_2\right)^2},\alpha =\tan ^{-1}\left(x_2-x_1,y_2-y_1\right),\beta =\cos ^{-1}\left(\frac{d^2+r_1^2-r_2^2}{2 d r_1}\right)$
页:
[1]