linmath

package
v0.0.0-...-0012533 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 11, 2023 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AngleToRadian

func AngleToRadian(angle float64) float64

角度转弧度

func AngleToVector

func AngleToVector(rota float64) Vector3

AngleToVector 将角度转换为方向向量

func CheckCalcPosBehind

func CheckCalcPosBehind(dstPos, checkPos Vector3, forwardAngle, angleOff int32) bool

检查某个点是否在背后 dstPos 原始对象位置 forwardAngle 原始对象朝向(角度) angleOff 正面的夹角半角(角度) checkPos 检查者位置

func CheckCirclePieIntersection

func CheckCirclePieIntersection(piepos Vector3, r float64, rota float64, angle float64, centpos Vector3, cr float64) bool

圆形和扇形是否相交 piepos扇形圆点 r 扇形半径 rota扇形弧度 angle扇形左右的弧度,*2表示扇形完整的弧度

centpos圆的圆心 cr圆的半径

func CheckCircleRectIntersection

func CheckCircleRectIntersection(centpos Vector3, r float64, p1, p2, p3, p4 Vector3) bool

判断圆与矩形是否相交 centpos圆心 r半径

p1,p2,p3,p4矩形的4个顶点

func CheckNavMeshTooFarAway

func CheckNavMeshTooFarAway(srcPos, dstPos Vector3, path []Vector3) bool

CheckNavMeshTooFarAway 怪物在寻路到达目标点时,如果寻路路径长度大于与目标的直线距离*2时,视为目标点不可寻路

func CheckPieContainsPoint

func CheckPieContainsPoint(piepos Vector3, r float64, startAngle float64, endAngle float64, pos Vector3) bool

判断点是否在扇形内

func CheckPointToLineDistance

func CheckPointToLineDistance(p Vector3, l1 Vector3, l2 Vector3) float64

求点到直线的距离

func Client2NavScale

func Client2NavScale(rawSize float32) float32

Client2NavScale 将客户端尺寸转换成导航网格尺寸,用于做动态阻挡尺寸转换

func ClientRota2Srv

func ClientRota2Srv(crota int32) (sRota int32)

客户端朝向转服务器朝向(U3D项目)

func GetCross

func GetCross(p1 Vector3, p2 Vector3, p Vector3) float64
计算 |p1 p2| X |p1 p|
这个函数是计算三维空间内一个点p是否在由p1和p2连成的线段的左侧(相对于p1→p2这个方向)。
该函数的实现方式是通过计算向量的叉积进行判断,叉积的值可以表示向量间的垂直度和方向关系。

具体来说,如果线段p1p2的方向向量为v, 则点p在向量v的左侧的条件是v和向量p1→p的叉积的z分量大于0。 如果z分量小于0,则p在v的右侧。 如果等于0,则p在v所在的直线上。

func GetPPosByRadians

func GetPPosByRadians(center, p0 Vector3, forward Vector3) Vector3

点P0,相对中心点center旋转forward向量所表示的角度

func GetPointInCircle

func GetPointInCircle(v Vector3, r float64) Vector3

GetPointInCircle 获取圆心为v,半径为r的圆中的随机点

func GetSign

func GetSign(diff float64) (sign float64)

GetSign 计算符号

func GetSquare4PPos

func GetSquare4PPos(center Vector3, length, width int, forward Vector3) (p1, p2, p3, p4 Vector3)

根据中心点和长宽和旋转角度,确定新的4个角坐标

func IntersectTwoCircles

func IntersectTwoCircles(c1, c2 Vector3, r1, r2 float64) (result1 *Vector3, result2 *Vector3)

计算两个圆的交点 返回值可能有0、1、2个交点(重合时只会有一个)

func IsPointInMatrix

func IsPointInMatrix(p1 Vector3, p2 Vector3, p3 Vector3, p4 Vector3, p Vector3) bool

判断点p是否在p1p2p3p4的正方形内

func PosClient2Nav

func PosClient2Nav(cPos *Vector3) (nPos Vector3)

PosClient2Nav 客户端位置转换成导航网格位置

func PosClient2Srv

func PosClient2Srv(cPos Vector3) (sPos Vector3)

PosClient2Srv 客户端位置转换成服务器位置 服务器Z指天,客户端Y指天

func PosMove

func PosMove(pos Vector3, rota, radius float64) Vector3

点pos根据角度rota,平移radius距离

func PosNav2Client

func PosNav2Client(nPos Vector3) (cPos Vector3)

PosNav2Client 导航网格位置转换成客户端位置

func PosNav2Srv

func PosNav2Srv(nPos Vector3) (sPos Vector3)

PosSrv2Nav 导航网格位置转换成服务器位置

func PosSrv2Client

func PosSrv2Client(sPos Vector3) (cPos Vector3)

PosSrv2Client 服务器位置转换成客户端位置

func PosSrv2Nav

func PosSrv2Nav(sPos Vector3) (nPos Vector3)

PosSrv2Nav 服务器位置转换成导航网格位置

func RadianToAngle

func RadianToAngle(radian float64) float64

弧度转角度

func UnwindDegrees

func UnwindDegrees(A float64) (R float64)

将度数限制在±180°

func VectorToAngle

func VectorToAngle(v Vector3) float64

VectorToAngle 将一个向量转化成角度,Y轴为垂直轴 在使用这个函数的时候,无需对向量归一化 向量转角度

func VectorToRadian

func VectorToRadian(v Vector3) float64

向量转弧度

func WindRelativeAnglesDegrees

func WindRelativeAnglesDegrees(angle0, angle1 float64) (retAngle float64)

这个函数是用来计算两个角度之间的相对角度差的函数。 WindRelativeAnglesDegrees 给定角度0,角度1(两个角度都是绝对角度数值,角度可以是任意未被归一成±180°), 返回角度0转向角度1之间夹角,值域为 ±180° 应用于怪物转向时候,需要计算角度差。比如:朝向是0°,需要转向到-179°,函数将会计算出-179°,而非181°

Given two angles in degrees, 'wind' the rotation in Angle1 so that it avoids >180 degree flips. 参考网址: https://docs.unrealengine.com/en-US/API/Runtime/Core/Math/FMath/WindRelativeAnglesDegrees/index.html https://github.com/suijingfeng/VulkanTutorials/blob/master/Engine/Monkey/Math/Math.cpp

《3D数学基础(第2版)》-第八章-P215 将插值方程中使用的角度之间的差异限制在(-180°,+180°]区间以内找到最短的弧。公式如下:

wrapPi(x)=x-360°floor((x+180°)/360°)

Types

type Rect

type Rect struct {
	MinX, MaxX int
	MinY, MaxY int
}

func NewRect

func NewRect(center *Vector2, size *Vector2) *Rect

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL