8.37. PikaMath 模块 API 文档

8.37.1. API

8.37.1.1. class Operator(TinyObj):

def plusInt(self,num1:int,num2:int)->int:...
def plusFloat(self,num1:float,num2:float)->float:...
def minusInt(self,num1:int,num2:int)->int:...
def minusFloat(self,num1:float,num2:float)->float:...
def equalInt(self,num1:int,num2:int)->int:...
def equalFloat(self,num1:float,num2:float)->int:...
def graterThanInt(self,num1:int,num2:int)->int:...
def graterThanFloat(self,num1:float,num2:float)->int:...
def lessThanInt(self,num1:int,num2:int)->int:...
def lessThanFloat(self,num1:float,num2:float)->int:...
def AND(self,flag1:int,flag2:int)->int:...
def OR(self,flag1:int,flag2:int)->int:...
def NOT(self,flag:int)->int:...
def __str__(self)->str:...
def __del__(self):...

8.37.1.2. class Math(TinyObj):

def __init__(self):...
def ceil(self,x:float)->int:...
def fabs(self,x:float)->float:...
def floor(self,x:float)->int:...
def fmod(self,x:float,y:float)->float:...
def remainder(self,x:float,y:float)->float:...
def trunc(self,x:float)->float:...
def exp(self,x:float)->float:...
def log(self,x:float)->float:...
def log2(self,x:float)->float:...
def log10(self,x:float)->float:...
def pow(self,x:float,y:float)->float:...
def sqrt(self,x:float)->float:...
def acos(self,x:float)->float:...
def asin(self,x:float)->float:...
def atan(self,x:float)->float:...
def atan2(self,x:float,y:float)->float:...
def cos(self,x:float)->float:...
def sin(self,x:float)->float:...
def tan(self,x:float)->float:...
def degrees(self,x:float)->float:...
def radians(self,x:float)->float:...
def cosh(self,x:float)->float:...
def sinh(self,x:float)->float:...
def tanh(self,x:float)->float:...

8.37.1.3. class Quaternion(TinyObj):

def __init__(self):...
def set(self,x:float,y:float,z:float,w:float):...
def get(self,key:int)->float:...
def add(self,quat:Quaternion):...
def sub(self,quat:Quaternion):...
def mul(self,quat:Quaternion):...
def magnituded(self)->float:...
def magnitudedsquare(self)->float:...
def reverse(self):...
def inverse(self):...
def normalize(self):...
def isnormalize(self)->int:...
def dot(self,quat:Quaternion)->float:...
def crossproduct(self,quat:Quaternion):...
def fromEuler(self,yaw:float,pitch:float,roll:float,mode:int):...
def toEuler(self)->list:...

8.37.2. Examples

8.37.2.1. Quaternion_test.py

from PikaMath import Quaternion

a=Quaternion()
a.set(0.592,0.158,0.592,0.525)

b=Quaternion()

a.add(b)
a.mul(b)


8.37.2.2. modbus_convert.py

def convert_to_modbus(num):
    # 判断输入数值的符号
    if num >= 0:
        sign = 0
    else:
        sign = 1

    # 如果是负数,将其转换为补码形式
    if sign:
        num = (~(-num) + 1) & 0xFFFF

    return num


def convert_from_modbus(num):
    # 判断输入数值的符号
    if (num & 0x8000):
        sign = 1
    else:
        sign = 0

    # 如果是负数,将其转换回原始的负数形式
    if sign:
        num = -((~num + 1) & 0xFFFF)

    return num


# 测试示例
num = -10
modbus_value = convert_to_modbus(num)

original_value = convert_from_modbus(modbus_value)

assert modbus_value == 65526
assert original_value == -10
print("PASS")