公切线&图像插值
今天水两题 = =
圆外切线
从简单的开始
最简单的两圆相切
令两圆参数分别为
{x1, y1, r1} = {0, 0, 1};
{x2, y2, r2} = {1, 2, 0.5};
用SOLVE解直线方程就可以
代码
distance[x_, y_, a_, b_] := Abs[a*x + b*y + 1]/Sqrt[a^2 + b^2];
{x1, y1, r1} = {0, 0, 1};
{x2, y2, r2} = {1, 2, 0.5};
result = Solve[
distance[x1, y1, a, b] == r1 && distance[x2, y2, a, b] == r2, {a,
b}]
con = ContourPlot[(a*x + b*y + 1 /. (# & /@ result)) == 0, {x, -3,
4}, {y, -3, 4}];
cons = Graphics[{Circle[{x1, y1}, r1], Circle[{x2, y2}, r2]}];
Show[con, cons]
在SOLVE有多解得时候可以用/.#&/@result来对每一个结果进行求解替代
推广(雾)
多圆的情况
不总是有解
所以没有必要(这个限制的太小了)
多余的推广😄
图像插值
对一个图像插值 可以画出这种条纹字符效果
如 MOK
text = Graphics[
Text[Style[" M O K ", FontSize -> 32,
FontFamily -> "Helvetica"], {0, 0}]]
textImage =
ImageCrop[Rasterize[Text@text, ImageSize -> 300], {300, 150}]
textImage = ColorConvert[Blur[textImage, 2], "Grayscale"]
{m, n} = Dimensions[ImageData[textImage]]
fun = Table[
ListInterpolation[ImageData[textImage][[i, ;;]]], {i, 1, 150}];
ListPointPlot3D[
Table[{i, k, 1 - fun[[i]][k]}, {i, 1, m, 2}, {k, 1, n, 0.1}],
Background -> Black, Boxed -> False, PlotStyle -> {White},
ImageSize -> 800, PlotRange -> {0, 1.5}]
结果如下
调参 = = 么么哒