Skip to main content

坐标工具类 LocationUtils

坐标工具类主要提供的是空间内坐标的 旋转, 判定 等方法

rotateLocationAboutPoint(Location location, double angle, Location point)

二维平面上利用给定的中心点逆时针旋转一个点

  • Location location 待旋转的点
  • double angle 旋转角度
  • Location point 中心点

注意: 此方法不会影响原来的 待旋转的点 而是会返回一个新的对象

rotateLocationAboutVector(Location location, Location origin, double angle, Vector axis)

给定两点建立向量后, 绕另一个向量旋转得到一个新的坐标点

  • Location location 待旋转的点
  • Location point 原点

    以上两个参数只用作建立向量

  • double angle 旋转角度
  • Vector axis 旋转向量轴
注意

此方法不会影响原来的 待旋转的点 而是会返回一个新的对象

该方法适用了 BukkitAPI 1.13 以上提供的方法, 请甄别版本后再使用

isPointInEntitySector(Location target, LivingEntity livingEntity, double radius, double angle)

判断一个是否处在实体面向的扇形区域内

通过反三角计算向量夹角进行判断

  • Location target 目标坐标
  • LivingEntity livingEntity 实体
  • double radius 扇形半径
  • double angle 扇形角度

如果处于扇形区域则返回 true

isInsideSector(Location target, LivingEntity livingEntity, double radius, double angle)

判断一个是否处在实体面向的扇形区域内

通过叉乘算法

  • Location target 目标坐标
  • LivingEntity livingEntity 实体
  • double radius 扇形半径
  • double angle 扇形角度

如果处于扇形区域则返回 true