This page has been translated automatically.
视频教程
界面
要领
高级
实用建议
UnigineEditor
界面概述
资产工作流程
设置和首选项
项目开发
调整节点参数
Setting Up Materials
Setting Up Properties
照明
Landscape Tool
Sandworm
使用编辑器工具执行特定任务
Extending Editor Functionality
嵌入式节点类型
Nodes
Objects
Effects
Decals
Light Sources
Geodetics
World Objects
Sound Objects
Pathfinding Objects
Players
编程
基本原理
搭建开发环境
Usage Examples
UnigineScript
C++
C#
UUSL (Unified UNIGINE Shader Language)
File Formats
Rebuilding the Engine Tools
GUI
应用程序接口
Containers
Common Functionality
Controls-Related Classes
Engine-Related Classes
Filesystem Functionality
GUI-Related Classes
Math Functionality
Node-Related Classes
Objects-Related Classes
Networking Functionality
Pathfinding-Related Classes
Physics-Related Classes
Plugins-Related Classes
IG Plugin
CIGIConnector Plugin
Rendering-Related Classes
注意! 这个版本的文档是过时的,因为它描述了一个较老的SDK版本!请切换到最新SDK版本的文档。
注意! 这个版本的文档描述了一个不再受支持的旧SDK版本!请升级到最新的SDK版本。

双精度坐标

警告
本文介绍的功能在 Community SDK 版本中不可用。
您应该升级到 Engineering / Sim SDK版本才能使用它。

There are cases when you need to calculate very large numbers (e.g. the distances in space), or, conversely, very small numbers (e.g. the distances in microcosm). In this regard, Unigine features a 64-bit double-precision floating-point format (instead of the 32-bit single-precision one) to define coordinates of objects in the virtual scene. Therefore, it is possible to create highly detailed virtually unlimited worlds (the maximum coordinates values are effectively 536,870,912 times larger than for the 32-bit float precision).在某些情况下,您需要计算非常大的数字(例如,空间中的距离),或者相反,需要计算非常小的数字(例如,微观中的距离)。在这方面,Unigine具有64位双精度浮点格式(而不是32位单精度浮点格式)来定义虚拟场景中对象的坐标。因此,可以创建几乎没有限制的高度详细的世界(最大坐标值实际上是32位浮点精度的536,870,912倍)。

In reality, float precision limitations are noticeable even on scenes larger than 10x10 km due to the accumulation of positioning errors, so double precision should be used for anything larger to maintain accuracy.实际上,由于定位误差的累积,即使在大于10x10 km的场景上,浮动精度限制也很明显,因此对于较大的任何物体都应使用双精度,以保持精度。

Single Precision versus Double Precision单精度与双精度#

In computing, floating point is a method of representing a real number by means of a mantissa and an exponent:在计算中,浮点是一种通过尾数和指数表示实数的方法:

mantissa ×  base  ^  exponent , mantissa ×  base  ^  exponent ,

where base is equal to 2.其中等于 2

The IEEE Standard for Floating-Point Arithmetic (IEEE 754) is a technical standard used both for float-precision and double-precision floating point formats. The single-precision floating point format occupies 32 bits (4 bytes), the double-precision floating point format occupies 64 bits (8 bytes). The number formats for both cases can be seen at the picture below: IEEE浮点算术标准(IEEE 754)是用于浮点精度和双精度浮点格式的技术标准。单精度浮点格式占用32位(4字节),双精度浮点格式占用64位(8字节)。两种情况的数字格式如下图所示:

Where:其中:

  • S - sign (0 - positive; 1 - negative) S-符号( 0 -正; 1 -负)
  • E - exponent (127 for single, 1023 for double) E-指数(单精度为 127 ,双精度为 1023
  • m - mantissa [1;2] m - 尾数 [1;2]

The distribution for the floating point format (both single and double) is subnormal. For instance, we have -1 ≤ E ≤ 2:浮点格式(单点和双点)的分布是次正态的。例如,我们有-1 ≤ E ≤ 2

The possible values range for single and double precision, as well as the minimal possible gradations are shown at the picture below.单精度和双精度的可能值范围以及最小可能的灰度如下图所示。

注意
Values that are set in UnigineEditor have the following limitations:
  • Values range: [-10^9;+10^9]. The lower and higher values will be displayed as inf.Values range: [-10^9;+10^9]. The lower and higher values will be displayed as inf.
  • The maximum quantity of the numbers in the fractional part cannot be more than 3.The maximum quantity of the numbers in the fractional part cannot be more than 3.

Values set by means of UnigineScript functions have only format's limitations.Values set by means of UnigineScript functions have only format's limitations.

Values range: [-10^9;+10^9]. The lower and higher values will be displayed as inf.The maximum quantity of the numbers in the fractional part cannot be more than 3.Values set by means of UnigineScript functions have only format's limitations.
在UnigineEditor中设置的值具有以下限制:
  • Values range: [-10^9;+10^9]. The lower and higher values will be displayed as inf.值范围:[-10^9;+10^9]。较低和较高的值将显示为 inf
  • The maximum quantity of the numbers in the fractional part cannot be more than 3.小数部分中数字的最大数量不能超过3。

Values set by means of UnigineScript functions have only format's limitations.通过UnigineScript函数设置的值仅具有格式限制。

Errors失误#

Usage of a single precision floating format leads to inaccurancies in calculations shown below.使用单精度浮点格式会导致如下所示的计算错误。

Positioning Error定位误差#

The large distance between possible graduations in the single-precision floating point leads to the positioning errors. The picture below schematically demonstrates the positioning while using single and double precision: 单精度浮点中可能的刻度之间的较大距离会导致定位错误。下图以示意图形式演示了使用单精度和双精度时的定位:

In the virtual scene, object transformations (including locating, rotating and scaling), animation and physics implementation lead to a positioning error, which, in turn, cause objects jittering. To avoid this problem and to provide far more precise positioning, use the double-precision floating point coordinates. Besides, positioning errors may lead to a vertex collapse that can be schematically seen at the picture below.在虚拟场景中,对象转换(包括定位,旋转和缩放),动画和物理实现会导致定位错误,进而导致对象抖动。为避免此问题并提供更精确的定位,请使用双精度浮点坐标。此外,定位错误可能导致顶点塌陷,如下图所示。

Error Accumulation错误累积#

As the numbers of the IEEE 754 format present a finite set, onto which the infinite set of real numbers is transmitted, the output value may consist a representation precision error, which in further calculations cause the error accumulation. The function of the error is shown below: 由于IEEE 754格式的数字表示一个有限的集合,在该集合上传输了无限的实数集合,因此输出值可能包含表示精度误差,这在进一步的计算中会导致误差累积。错误的功能如下所示:

The maximum absolute error for a number is equal to the half of the possible gradation. As the possible gradation is doubled when the exponent is incremented, the error is increased too.一个数字的最大绝对误差等于可能的灰度的一半。当指数增加时,可能的灰度会加倍,因此误差也会增加。

The gradation of the numbers equals to 2 ^ (E-150) for single-precision numbers, and 2 ^ (E-1075) for double-precision numbers.对于单精度数字,数字的等级等于2 ^ (E-150),对于双精度数字,数字的等级等于2 ^ (E-1075)

Lets compare the 1 value for both single-precision and double-precision numbers.让我们比较单精度数字和双精度数字的 1 值。

单精度 双精度
数字(十进制) 1.0 1.0 1.0 1.0
IEEE754(十六进制) 3F800000 3F800000 3FF00000 00000000 3FF00000 00000000
绝对误差(十进制) 2 -23 ≈ 1.192*10 -7 2 -23 ≈1.192 * 10 -7 2 -52 ≈ 2.220446*10 -16 2 -52 ≈2.220446 * 10 -16
相对误差, % 11.9209*10 -6 11.9209 * 10 -6 2.220446*10 -14 2.220446 * 10 -14

According to the distribution, the gradation values are increasing, which leads to the error increase. But in comparison, the double-precision numbers error is many times less than the single-precision numbers errors.根据分布,灰度值增加,导致误差增加。但是相比之下,双精度数字错误要比单精度数字错误小很多倍。

最新更新: 2021-04-09
Build: ()