physics test
This commit is contained in:
@ -3,35 +3,54 @@ package itemprops
|
||||
import "github.com/shopspring/decimal"
|
||||
|
||||
type ItemPhysics struct {
|
||||
Material Material
|
||||
Rigidity DimensionItemRigidity
|
||||
Size DimensionItemSize
|
||||
Temperature DimensionItemTemperature
|
||||
Material `json:"material"`
|
||||
//DimensionItemRigidity жёсткость (самого предмета а не материала), мера прочности,
|
||||
//уменьшается со временем, может зависеть от тепмературы
|
||||
DimensionItemRigidity `json:"rigidity"`
|
||||
DimensionItemSize `json:"size"`
|
||||
DimensionItemTemperature `json:"temperature"`
|
||||
//CubeFactor фактор близости куб <-> сфера по площади поверхности, чем ближе к 0, тем ближе к сфере,
|
||||
//100 - куб, >100 - для суперсложных (шипастых например) поверхностей
|
||||
CubeFactor decimal.NullDecimal `json:"cube_factor,omitempty"`
|
||||
}
|
||||
|
||||
//DimensionItemSize length in m (1 mm = 1/1000 of 1m)
|
||||
// DimensionItemSize length in m (1 mm = 1/1000 of 1m)
|
||||
type DimensionItemSize struct {
|
||||
Width decimal.Decimal
|
||||
Height decimal.Decimal
|
||||
// if item is solid - depth in m (1mm = 1/1000 of m)
|
||||
Depth decimal.NullDecimal
|
||||
//Thickness if item is hollow - thickness of outer item shell, ie for armor, in m (1 mm = 1/1000 of m)
|
||||
Thickness decimal.NullDecimal
|
||||
Width decimal.Decimal `json:"width"`
|
||||
Height decimal.Decimal `json:"height"`
|
||||
// if item is solid - depth in m (1mm = 1/1000 of m)
|
||||
Depth decimal.NullDecimal `json:"depth,omitempty"`
|
||||
//Thickness if item is hollow - thickness of outer item shell, ie for armor, in m (1 mm = 1/1000 of m)
|
||||
Thickness decimal.NullDecimal `json:"thickness,omitempty"`
|
||||
}
|
||||
|
||||
//Area is frontal area
|
||||
// Area is frontal area
|
||||
func (d *DimensionItemSize) Area() decimal.Decimal {
|
||||
return d.Width.Mul(d.Height)
|
||||
return d.Width.Mul(d.Height)
|
||||
}
|
||||
|
||||
//DimensionItemDensity density in kg/m3
|
||||
type DimensionItemDensity decimal.Decimal
|
||||
func (ip *ItemPhysics) Weight() decimal.Decimal {
|
||||
return ip.Material.Density.Mul(ip.Volume())
|
||||
}
|
||||
|
||||
//DimensionItemRigidity rigidity жёсткость, способность твёрдого тела, конструкции или её элементов сопротивляться деформации in N/m
|
||||
type DimensionItemRigidity decimal.Decimal
|
||||
|
||||
//NotchFractureToughness ударная вязкость по Шарпи, Дж (надо ли?)
|
||||
type NotchFractureToughness decimal.Decimal
|
||||
|
||||
//DimensionItemTemperature in celsius, -273 to 10000
|
||||
type DimensionItemTemperature decimal.Decimal
|
||||
func (d *ItemPhysics) Volume() decimal.Decimal {
|
||||
v := d.Width.Mul(d.Height)
|
||||
//есть глубина
|
||||
if !d.Depth.Decimal.IsZero() {
|
||||
v = v.Mul(d.Depth.Decimal)
|
||||
//пустотелый
|
||||
if !d.Thickness.Decimal.IsZero() {
|
||||
surfaceArea := d.Width.Mul(d.Height).Mul(decimal.NewFromInt(2)).
|
||||
Add(d.Height.Mul(d.Depth.Decimal).Mul(decimal.NewFromInt(2))).
|
||||
Add(d.Width.Mul(d.Depth.Decimal).Mul(decimal.NewFromInt(2)))
|
||||
surfaceAreaCoeff := 0.85
|
||||
if !d.CubeFactor.Decimal.IsZero() {
|
||||
surfaceAreaCoeff = surfaceAreaCoeff * float64(int(d.CubeFactor.Decimal.IntPart())/100)
|
||||
}
|
||||
v = surfaceArea.Mul(d.Thickness.Decimal).
|
||||
//волюнтаристский коэффт отличия поверхности от куба, см https/en.wikipedia.org/wiki/Volume-to-surface_area_ratio
|
||||
Mul(decimal.NewFromFloat(surfaceAreaCoeff))
|
||||
}
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
Reference in New Issue
Block a user