前言:无论是乘法公式的,还是这个视频中的一种非常规nx的方法,它们都是基于(逆)旋转公式将A的局部坐标系转换为绝对坐标系,再生成一条长度为AB的线,随后再通过旋转公式转回A的视角
这个过程就是:(逆)旋转公式→生成长度为AB的线→旋转公式
因此我们实际上只要解决一个问题:“如何生成一条长度为AB的线?”
乘法公式的方法我在 BV1VPu166EKD 解释过原理,这里就不赘述了
你可能有见过两实体之间连线的命令,这里是@凛吁 大大的 BV1LCdRYtE5P 中的修改版(感谢@凛吁 大大提出的方法!)
我们可以由这个来解释这种nx方法
如果我们把AB两点间的距离当作初始值,AB中点作为初始执行位置
那么nx一层相当于由初始点向A、B各延伸AB/4
nx二层相当于在一层基础处上再向A、B各延伸AB/8
……
nxn层相当于在上一层基础上向A、B各延伸AB/[2^(n+1)]
注:此处实际的运算过程没有那么简单,并不是简单一直/2的,不过……不影响后续理解,最终效果是相同的
我们可以用nx的形式来实现这个过程!
先将AB平移到原点
使用(逆)旋转公式将AB储存在Y坐标中,现在坐标为(0,AB,0)
使用缩放公式将Y坐标变为AB/2,(0,AB,0)→(0,AB/2,0)
使用大数圆规将AB/2储存在X坐标中,(0,AB/2,0)→(AB/2,AB/2,0)
那么我们现在已知中点与AB/2的长度,它们分别储存在X、Y中
接下来所要做的就是“在第n层向X轴正负各延伸AB/[2^(n+1)]”
尽管XY总是在变化,但是对于大数a来说,这些变化是可以不计的,因此我们依旧可以通过facing绝对坐标的方式来进行坐标运算
(实际中也确实如此,尽管你可以通过引入Z轴的方式来使精度提高,不过我不建议这么做)
(后面会提到原因)

nx的过程
我们可以这样设计每一次延伸:
1. rotated两个分别朝向X轴正负的实体,读取Y坐标(在第一次读取时是AB/2)并将其记为y,并/2(本次要延伸的距离)
2. 将读取到的y/2转到X坐标上
首先是读取y并将其/2:
rotated as @e[name=nx] positioned ^ ^ ^a facing 0 0 ~ (读取y)
posotioned ^ ^ ^a/2 (缩放/2)
rotated ~ 0 positioned ^ ^ ^a/2 (回到原处)
接着再将y/2转到X坐标上:
positioned ^ ^ ^a facing 0 0 ~ (读取y/2)
positioned ^ ^a/2 ^ positioned ~ ~-a/2 ~ (将y/2转到X坐标上)
rotated ~ 0 positioned ^ ^ ^a/2 (回到原处)
这条命令实在是太臃肿了!我们必须得优化一下,否则会很卡的……
我想你应该发现了:在第二步中有一个positioned ~ ~-a/2 ~,而之后的rotated ~ 0恰好使得^ ^-a/2 ^就相当于~ ~-a/2 ~的效果
因此我们可以这么写第二条命令:
positioned ^ ^ ^a facing 0 0 ~ positioned ^ ^a/2 ^ rotated ~ 0 positioned ^ ^-a/2 ^a/2
我们把两部分放在一块看一看
rotated as @e[name=nx] positioned ^ ^ ^a facing 0 0 ~ posotioned ^ ^ ^a/2 rotated ~ 0 positioned ^ ^ ^a/2
positioned ^ ^ ^a facing 0 0 ~ positioned ^ ^a/2 ^ rotated ~ 0 positioned ^ ^-a/2 ^a/2
有发现吗?两部分读取的过程是可以合并在一块的,而且回到原位置的过程也是可以合并的
因此我们把回到原处的部分放到最后,把两个读取再运算的过程合并到一块儿
rotated as @e[name=nx] positioned ^ ^ ^a facing 0 0 ~ (读取y)
posotioned ^ ^a/2 ^a/2 (y/2的同时将y/2转到X坐标上)
rotated ~ 0 positioned ^ ^-a/2 ^a/2 (回到原处)
这样我们就得到了:
rotated as @e[name=nx] positioned ^ ^ ^a facing 0 0 ~ posotioned ^ ^a/2 ^a/2 rotated ~ 0 positioned ^ ^-a/2 ^a/2
不断重复这个过程
这样,我们就得到了一条长度为AB的线
将所有点的Y坐标归零并将X坐标转为Y坐标
接着,只要再用旋转公式将这得到线转到A的视角再移到A处就可以了
为什么不引入Z轴或者使用rotated ~180 ~这样的方式使精度更高?
因为nx时,点的数量是越来越多的
这也就意味着哪怕nx之后只有一条子命令,它可能也在不同位置执行很多次
因此,nx后的子命令的数量要尽量少一些
引入Z轴或者rotated ~180 ~式的虽然精度更高,但子命令也更多
比起在nx之后提高精度,我觉得在nx之前,把AB的长度缩放更高些
这也是为什么在乘法公式和本期视频里,我都把AB/16
-------------------------------
以下是原指令
-------------------------------
(需要两个名字为nx的盔甲架,分别面向Z轴正负方向)
execute as @e[name=P] at @e[name=P] if score @s Uid1 = @e[name=P,c=1] Uid0 facing entity @s feet positioned as @s run tp ~ ~ ~ facing ^ ^ ^-1
优化后的版本
execute as @e[name=P] at @e[name=P] if score @s Uid1 = @e[name=P,c=1] Uid0 rotated as @s positioned ^ ^500000 ^ facing entity @s feet positioned 0 0 0 positioned ^ ^ ^-31250 rotated as @s positioned ^10000 ^-31250 ^10000 facing 0 0 0 positioned ^ ^ ^28284.27124746 rotated as @s positioned ^ ^ ^10000 positioned ~ ~-10000 ~ facing 0 0 0 positioned ^ ^ ^28284.27124746 rotated as @s positioned ^-10000 ^ ^ facing 10000 10000 ~ positioned ^ ^5000 ^5000 positioned ~-5000 ~-5000 0 rotated as @e[name=nx] positioned ^ ^ ^10000 facing 0 10000 ~ positioned ^ ^5000 ^5000 rotated ~ 0 positioned ^ ^-5000 ^5000 positioned ~ 0 ~ facing 0 ~10000 ~ positioned ^ ^10000 ^ positioned 0 ~ 0 rotated as @s positioned ^-10000 ^ ^ positioned ~ ~-10000 ~ facing 0 0 0 positioned ^ ^ ^28284.27124746 rotated as @s positioned ^ ^ ^10000 positioned ~ ~-10000 ~ facing 0 0 0 positioned ^ ^ ^28284.27124746 rotated as @s positioned ^10000 ^10000 ^10000 facing 0 0 0 positioned as @s positioned ^ ^ ^-160000 rotated as @s positioned ^ ^-160000 ^ run particle minecraft:balloon_gas_particle ~ ~
重复标注的部分可以控制点的数量,重复n次最后点为2^n个
带有注释的版本(下面的a、A都是大数,最好a≥10000,A≥500000)
筛选出与该实体连线的实体
execute as @e[name=P] at @e[name=P] if score @s Uid1 = @e[name=P,c=1] Uid0
大数圆规:将AB平移到原点并/16
rotated as @s positioned ^ ^A ^ facing entity @s feet positioned 0 0 0 positioned ^ ^ ^-A/16 rotated as @s positioned ^ ^-A/16 ^
(逆)旋转公式:将AB/16竖放到Y轴
rotated as @s positioned ^a ^ ^a facing 0 0 0 positioned ^ ^ ^2√2a rotated as @s positioned ^ ^ ^a positioned ~ ~-a ~ facing 0 0 0 positioned ^ ^ ^2√2a rotated as @s positioned ^-a ^ ^ positioned ~ ~-a ~
大数圆规:(0,AB/16,0)→((AB/16)/2,(AB/16)/2,0)
facing a 0 ~ positioned ^ ^a/2 ^a/2 positioned ~-a/2 ~-a/2 0
nx:重复该步骤n次最终会得到2^n个点
rotated as @e[name=nx] positioned ^ ^ ^a facing 0 0 ~ positioned ^ ^a/2 ^a/2 rotated ~ 0 positioned ^ ^-a/2 ^a/2
使Y坐标归零
positioned ~ 0 ~
大数圆规:将X坐标转为Y坐标
facing 0 ~a ~ positioned ^ ^a ^ positioned 0 ~ 0
旋转公式:将得到的线旋转到A的视角
rotated as @s positioned ^-a ^ ^ positioned ~ ~-a ~ facing 0 0 0 positioned ^ ^ ^2√2a rotated as @s positioned ^ ^ ^a positioned ~ ~-a ~ facing 0 0 0 positioned ^ ^ ^2√2a rotated as @s positioned ^a ^ ^a
大数圆规:将得到的线移到A处并*16
rotated as @s positioned ^ ^a ^ facing 0 0 0 positioned as @s positioned ^ ^ ^-16a rotated as @s positioned ^ ^-16a ^
生成粒子
run particle minecraft:balloon_gas_particle ~ ~ ~
用于解释优化过程的版本
execute as @e[name=P] at @e[name=P] if score @s Uid1 = @e[name=P,c=1] Uid0
rotated as @s positioned ^ ^A ^ facing entity @s feet positioned 0 0 0 positioned ^ ^ ^-A/16 rotated as @s positioned ^ ^-A/16 ^
这里上下同为rotated as @s positioned ^ ^ ^,因此可以合并为rotated as @s positioned ^a ^-A/16 ^a
rotated as @s positioned ^a ^ ^a facing 0 0 0 positioned ^ ^ ^2√2a rotated as @s positioned ^ ^ ^a positioned ~ ~-a ~ facing 0 0 0 positioned ^ ^ ^2√2a rotated as @s positioned ^-a ^ ^ positioned ~ ~-a ~
这里把上面的positioned ~ ~-a ~去掉后,相当于把整个坐标系抬高了a,因此需要把之后的绝对Y坐标均+a
facing a 0+a ~ positioned ^ ^a/2 ^a/2 positioned ~-a/2 ~-a/2 0
rotated as @e[name=nx] positioned ^ ^ ^a facing 0 0+a ~ positioned ^ ^a/2 ^a/2 rotated ~ 0 positioned ^ ^-a/2 ^a/2
positioned ~ 0 ~
facing 0 ~a ~ positioned ^ ^a ^ positioned 0 ~ 0
rotated as @s positioned ^-a ^ ^ positioned ~ ~-a ~ facing 0 0 0 positioned ^ ^ ^2√2a rotated as @s positioned ^ ^ ^a positioned ~ ~-a ~ facing 0 0 0 positioned ^ ^ ^2√2a rotated as @s positioned ^a ^ ^a
这里上下同为rotated as @s positioned ^ ^ ^,因此可以合并为rotated as @s positioned ^a ^a ^a
rotated as @s positioned ^ ^a ^ facing 0 0 0 positioned as @s positioned ^ ^ ^-16a rotated as @s positioned ^ ^-16a ^
run particle minecraft:balloon_gas_particle ~ ~ ~
免责声明:本文系网络转载或改编,未找到原创作者,版权归原作者所有。如涉及版权,请联系删