<<

Rendering Non-Euclidean in Real-Time Using Spherical and Hyperbolic

Daniil Osudin Dr Chris Child Prof Yang-Hui He

City, University of London

08/06/2019 arXiv:1908.01742v1 [cs.GR] 5 Aug 2019 Contents

1 Abstract 2

2 Introduction 2

3 Method 3 3.1 Polar coordinates ...... 3 3.2 Projection ...... 3 3.3 Mathematical analysis ...... 4 3.3.1 Rendering the shape ...... 4 3.3.2 Updating object position ...... 7

4 Results 8 4.1 Engine ...... 8 4.2 Complexity Analysis ...... 10

5 Discussion 10

6 Conclusion 11

1 (a) Spherical timelapse (b) Spherical space timelapse (c) Hyperbolic space timelapse Figure 1: Time-lapse images of multiple objects moving through spherical (a), planar (b) and hyperbolic (c) 2D space calculated and rendered by the physics/graphics engine described below

1 Abstract encompasses any geometry that arises from either changing the postulate (’s fifth pos- This paper introduces a method of calculating and tulate) or the metric requirement. In this study we rendering shapes in a non-Euclidean 2D space. In will be focussing solely on traditional non-Euclidean order to achieve this, we developed a physics and 2D : Spherical geometry and Hyperbolic graphics engine that uses hyperbolic trigonometry geometry, illustrated on Figure 2 (a) and (c) respec- to calculate and subsequently render the shapes in tively. a 2D space of constant negative or positive curva- ture in real-time. We have chosen to use polar co- ordinates to record the parameters of the objects as well as an azimuthal equidistant projection to render the space onto the screen because of the multiple useful properties they have. For example, (a) Spherical (c) Euclidean (b) Hyperbolic polar coordinate system works well with trigono- Figure 2: Comparison of parallel lines in the 2D metric calculations, due to the distance from the of different curvature reference (analogous to origin in Cartesian In spherical geometry all (straight coordinates) being one of the coordinates by def- lines in a non-planar space) intersect, so there are inition. Azimuthal equidistant projection is not a no parallel lines. Even if the lines start parallel, typical projection, used for neither spherical nor hy- they don’t preserve the same distance along their perbolic space, however one of the main features of and instead appear to ‘bend’ towards each our engine relies on it: changing the curvature of other. In fact any two great will intersect the world in real-time without stopping the execu- twice (unless they are one and the same). Spheri- tion of the application in order to re-calculate the cal geometry is used in multiple fields: navigation, world. This is due to the projection properties that GPS, architecture and aerospace engineering among work identically for both spherical and hyperbolic others. However in most circumstances the calcula- space, as can be seen in the Figure 1 above. We tions are done on a surface of a 3D instead will also be looking at the complexity analysis of of the 2D spherical , and rendering if any uses this method as well as renderings that the engine the orthographic projection of the sphere. Figure 3 produces. Finally we will be discussing the limita- below, for example, illustrates Earth’s eastern hemi- tions and possible applications of the created engine sphere: as well as potential improvements of the described method. 2 Introduction

Non- is a broad subject that takes its origin from Euclid’s work Elements [1], where he defined his five postulates. This field Figure 3: Orthographic projection of the sphere [2]

2 In cartography, multiple other projections are 3 Method used and one of them has been chosen by us to be a focus of this study: Azimuthal equidistant pro- The method chosen is using hyperbolic and spher- jection. A detailed explanation of this projection ical trigonometry, as well as equidistant azimuthal and its advantages for this model is described in projection and polar coordinates system in order to the Method section. calculate object positions and render the objects in In , any can have an an arbitrary 2D space of constant positive or nega- infinite number of parallel lines, as the lines appear tive curvature. to ‘bend’ away from each other. Elliptic geome- try is more tangible and intuitive than hyperbolic geometry, due to people interacting with it more 3.1 Polar coordinates and the possibility of a 2D elliptic plane to be em- bedded into a 3D space. Hyperbolic geometry is more abstract; however it is used heavily in mathe- y matics, astrophysics and theoretical physics, partic- A ularly for calculations involving general relativity. r Θ x The usual projection used to represent hyperbolic geometry is the Poincare disc. O

Figure 5: Position of a point A in polar coordinates. It has distance r and bearing θ from the reference point O

A polar coordinate system of the form (r, θ) is used in this model for all of the object positions and Figure 4: Poincare disc with hyperbolic tiling [3] calculations instead of Cartesian coordinates. The centre of the of the screen is taken as a reference point (analogous to the origin point in Cartesian Our aim was to create a physics and graphics coordinates) for the distance coordinate, r, while engine capable of calculating and rendering objects eastbound direction is set to be the reference direc- in a 2D space of arbitrary constant curvature. Our tion for the bearing coordinate, θ. additional objective was to make it possible for the Cartesian coordinates need to be adapted in curvature to be modified in real-time during the ex- order to be used for constant negative and posi- ecution of the engine. We approached this by devel- tive curvature spaces, as the parallel lines, which oping a method of calculating the object’s position are essential to pinpoint the location in Carte- as well as the vertices of its shape in polar coordi- sian space, are fundamentally different in a non- nates using spherical [4] or hyperbolic trigonome- Euclidean space. try [5] [6] and then rendering the objects onto the On the other hand, polar coordinates work just screen using an azimuthal equidistant projection. as well in any space of constant curvature, as the The real-time change of curvature was achieved by distance from a reference point and bearing from a having the shapes of the object’s dynamically recal- reference direction still exist. This principle will culated in order to always use the current curvature help unify the coordinate system for any curva- variable. ture of the space and ultimately allow the real-time Figure 1 above shows the time-lapse results of change of curvature without any complications. the engine rendering multiple objects in spherical (a), planar (b) and hyperbolic (c) geometries. The resulting engine can be used and built upon for 3.2 Projection multiple different purposes, such as creating video games or animations in non-Euclidean environment, In order to render a non-Euclidean 2D space onto a help visualise the mathematics of non-Euclidean flat screen, a projection has to be used which trans- space and create tools for use in different of late the points in a curved space onto a flat 2D space research. that is a screen.

3

1

Shape has a List of position vectors for each . r = 1 These vectors are defined in local coordinates with the reference point being the centre of the object (point defined by object’s position vector in global coordinates) and reference direction is taken as the opposite of the object’s position vector (illustrated l = 6.28 on the Figure 8 below). This method simplifies the trigonometric calculations explained in the follow- Figure 6: Side view of unfolding a sphere or radius ing subsections. All of the vertices are defined to r onto a plane of size l using Azimuthal Equidistant be connected by the edges that lie on the geodesics projection. The diagram is to scale. which standardizes the definition of the object in a We chose to use azimuthal equidistant projec- way that is independent of the world’s curvature. tion, as this projection has useful properties that fit As such, in order to have a shape with a curved the purpose well. Firstly, by definition, distances edge (e.g. semicircle), multiple vertices will need to and bearing from the centre of the projection are be set to represent the curved edge. preserved. This fits perfectly with the Polar co- V ordinates: for any point, its position vector on the 3 projection is the position vector in the curved space. Secondly, this projection is intuitive, so makes the V4 C non-Euclidean geometry easier to understand. Fi- nally, this projection can be used with no change to ϴ1 V2 O r1 O’ represent both spherical and hyperbolic 2D spaces. C’

3.3 Mathematical analysis V1

The calculations in this model are split into two Figure 7: Local coordinate system of the object. parts: movement of the objects and rendering of Key: O, the reference point with coordinates (0, 0); the shapes, so the analysis will also be split into the C, position of the object and reference point of the corresponding subsections. Initially, it is important local coordinate system with coordinates (rc, θc); to overview how the model is structured and how V , vertex of the illustrated object with local co- the objects, shapes and the space are defined in the 1 ordinates (r1, θ1); V1,V2,V3, other vertices; OO’, model. reference direction; CC’, local reference direction First, as previously mentioned, the model uses a polar coordinate system for all calculations and Note: Diagrams below are shown in planar ge- these are only converted into Cartesian coordinates ometry in order to keep them clear, the is for the final step of rendering, in order to utilise still a good representation for the analogous spher- the rendering functions available through OpenGL. ical and hyperbolic that arise depending Hence, when a vector is mentioned in this section,1 on the world curvature setting. This is because all we are referring to a Polar Vector in a form (r, θ). of the known values remain unchanged irrespective The screen (rendering space) is limited to a cir- of curvature, as they are pre-set by definition of the cle of an arbitrary size. When the object’s centre shape and object in the engine. moves past the of the , it is repo- sitioned to the antipodal point on the circle with the velocity preserved. This is implemented in order to keep the objects in the visible on the screen. 3.3.1 Rendering the shape Each object has a set of parameters that con- tain its properties, essential for the calculations de- In order to render the shape, global coordinates scribed in this section. have to be calculated for all of the vertices of the Object variables: shape. This model is using spherical and hyperbolic • Position vector trigonometry in order to calculate these values. • Velocity vector Let K ∈ [−1, 1] ⊂ < s.t. • Acceleration vector K = 0 ⇒ Euclidean Geometry • K > 0 ⇒ Spherical Geometry, r = √1 • Rotation speed K • Shape K < 0 ⇒ Hyperbolic Geometry, k = √1 K

4

w u u b b C C w a a c c v v

Figure 8: Spherical triangle on the surface of a sphere Figure 9: on the surface of a hyperbolic plane Theorem 1 For a sphere of radius r and hence 1 K = r2 , as well as a spherical triangle on its surface described by points u, v and Theorem 2 For a hyperbolic plane with Gaussian Curvature K = − 1 and a hyperbolic triangle on its w, connected by great circles that form the edges a, k2 b, c (interpreted as subtended ) and an an- surface described by points u, v and w, connected gle C (See figure 8), the spherical by geodesics that form the edges a, b and c, as well states: [7] as an angle C (See figure 9), the hyperbolic law of cosines states: [8] c a b a b cos = cos cos + sin sin cos C (1) r r r r r c a b a b cosh = cosh cosh − sinh sinh cos C (2) k k k k k

C’ V(rv, ϴv), C(rc, ϴc) in polar ϴc ϴ V coordinate system with O c O’ α a reference point O rlocal C OV = rv, OC = rc, CV = rlocal Δϴ r ϴlocal ∠VOO’ = ϴv, ∠OCV = β, v α β rc ∠COO’ = ϴc, ∠VOC = Δϴ, C’ rv rc ∠OCC’ = α, ∠VCC’ = ϴ β local V Δϴ ϴ local ϴc ϴv O’ rlocal C O

(a) (b) Figure 10: Finding the θ and r coordinates of an object’s vertices through a hyperbolic/spherical triangle OCV . Key: O, reference point of the global polar coordinate system with coordinates (0, 0); C, position of the object with coordinates (rc, θc) and origin of the local polar coordinate system of the object; V, vertex of the object with global coordinates ( r, θ) and local coordinates (rlocal, θlocal); α, object’s angle of rotation in local coordinates; β, angle between object position vector (line OC) and line from centre of the object to the vertex position (line CV). Case (a): Sum of θlocal and α is less than π; case (b): sum of θlocal and α is more than π

Note: in order to simplify the equations below, Find: rv, θv = ? all of the will be divided by r or k depend- If K > 0, then: ing on the value of K. Then the lengths that we are rv = arccos (cos rc cos rlocal + sin rc searching for will be multiplied by r or k to get the (3) final answer. sin rlocal cos β)

cos rlocal − cos rc cos rv Corollary 1 Given: O(0, 0),C(rc, θc),V(rv, θv), ∆θv = arccos ( ) (4) sin rcsinrv OC = rc, CV = rlocal, 6 COO’ = θc, 6 OCC’ = α, 6 VCC’ = θlocal

5 If K < 0, then: In order to find rv, we first find 6 OCV = β. β = α + θlocal; however if Π < β < 2Π, use the rv = arccosh (cosh rc cosh rlocal − sinh rc (5) explementary angle of β instead. This is done to sinh rlocal cos β) determine to which side of OC the triangle lies, which will be used to find θv. In order to find θv, cosh rc cosh rv − cosh rlocal we calculate 6 VOC = ∆θ, which is then added to ∆θv = arccos ( ) (6) sinh rc sinh rv or subtracted from θc, depending on whether the ex- plementary angle of β was taken or not.

ϴ V1(r1, ϴ1), V2(r2, ϴ2), ϴ1 ϴ2 ϴ 1 O’ ϴ O’ c ϴ2 c C(rc, ϴc) in polar O O coordinate system with r 1 a reference point O Δϴ2 Δϴ1 Δϴ1 OV1 = r1, CV1 = r1local, r2 V1 r1 Δϴ2 OV2 = r2, CV2 = r2local, rc OC = rc rc ∠ ∠ V2 d V1 V1OO’ = ϴ1, V2OO’ = ϴ2, r1local ∠COO’ = ϴc, ∠V1OC = Δϴ1, ∠ r1local V2OC = Δϴ2 r2local C C d r2

r2local

V2

(a) (b) Figure 11: Finding preliminaries to calculate intermediate points between two vertices: the length of the edge as well as the angle between the position vectors of the two vertices of this edge. Key: O, reference point of the global coordinate system; C, position of the object; V1,V2, vertices of the object; d, edge V1V2; r1, r2, r coordinates of the respective vertex; ∆θ1, ∆θ2, difference between θ coordinate of C and the respective vertex; r1local, r2local, r coordinates of the respective vertex in local coordinates. Overall ∆θ is the angle between r1 and r2. And there are two cases to be considered. In the first case the angles ∆θ1and∆θ2 are diverging (a), so ∆θ is the sum of these angles; the second case is when these angles converge, in which case ∆θ is the absolute value of the difference between the two angles. Note: The above steps need to be repeated to find every vertex of an object. However that is Here we could have 2 cases: diverging angles and not enough information to draw curved lines onto a converging angles (see diagram 10). screen. In order to proceed with rendering, a geod- Angles diverge if ∆θ1 < 0, ∆θ2 < 0 or ∆θ1 > 0, sic between the two vertices should be tessellated ∆θ2 > 0. Then: into smaller straight lines, which could be rendered ∆θ = k∆θ1k + k∆θ2k (9) on the screen. Hence intermediate points should be found along the lines connecting the vertices of the Angles converge if ∆θ > 0, ∆θ < 0 or ∆θ < shape. To find them, we need to find the length 1 2 1 0, ∆θ > 0. Then: of the edge between the two vetices as well as the 2 total angle between the position vectors of the two ∆θ = k∆θ1 − ∆θ2k (10) vertices (illustrated on the figure 11 above). In order to find d, consider 4OV V . Corollary 2 Given: O(0, 0),C(r , θ ), 1 2 c c If K > 0, then: V1(r1, θ1),V2(r2, θ2), OC = rc, OV1 = r1, OV2 = r2, CV1 = r1local, CV2 = r2local, 6 COO’ = d = arccos (cos r1 cos r2 + sin r1 6 6 (11) θc, V1OO’ = θ1, V2OO’ = θ2 sin r2 cos ∆θ) Find: d, ∆θ = ? In order to find ∆θ, we first find ∆θ1 and ∆θ2: If K < 0, then:

∆θ = θ − θ (7) d = arccosh (cosh r1 cosh r2 sinh r1 1 c 1 (12) sinh r2 cos ∆θ) ∆θ2 = θc − θ2 (8)

6 Note: We also need to record which of ∆θ1 and If K > 0, then: ∆θ is the greater angle, as that determines the di- 2 cos r2 − cos r1 cos d rection of the edge d used in the next step. α = arccos ( ) (13) sin r1 sin d V (r , ϴ ), V (r , ϴ ), 1 1 1 2 2 2 r = arccos (cos r cos d + sin r ϴ1 V (r , ϴ ) in polar i 1 i 1 ϴ O’ i i i (14) ϴ2 i coordinate system with sin d cos α) O i r a reference point O Δϴ 2 cos di − cos r1 cos ri r Δϴi OV1 = r1, OV2 = r2, OVi = ri, ∆θi = arccos ( ) (15) 1 V2 sin r sin r ri V1V2 = d, V1Vi = di 1 i α ∠V1OO’ = ϴ1, ∠V2OO’ = ϴ2, V1 d If K < 0, then: Vi di ∠ViOO’ = ϴi, ∠V1OV2 = Δϴ, ∠V OV = Δϴ , ∠OV V = α cosh r1 cosh d − cosh r2 C 1 i i 1 i α = arccos ( ) (16) sinh r1 sinh d

ri = arccosh (cosh r1 cosh di sinh r1 (17) sinh di cos α)

Figure 12: Finding Intermediate points between cosh r1 cosh ri − cosh di two vertices in order to render the edge. Key: O, ∆θi = arccos ( ) (18) sinh r1 sinh ri reference point of the global coordinate system; C, position of the object; V1,V2, vertices of the object; Angle α is calculated as an inbetween step to find d, edge V1V2; Vi, point on d; r1, r2, ri, r coordinates the angle opposite ri to apply the rule of cosines. of the respective point; ∆θi, difference between θ Then ri and subsequently ∆θi can be found using coordinate of V1 and Vi; ∆θ, angle between OV1 the cosine rule. To calculate the distance ri, the and OV2 triangle V1OVi is considered. Using the previously found angle α as well as the known lengths r and Note: distance d is divided into a number of 1 V V (d ) a hyperbolic/spherical cosine rule can be equal parts in order to find the distance d for each 1 i i i applied (illustrated on figure 12). of the points on the edge V V . The number of 1 2 Then to find actual coordinates of the point V , segments depends on the object tesselation vaiable. i ri should be multiplied by r or k depending on the

Corollary 3 Given: O(0, 0),V1(r1, θ1), value of K; ∆θi should be added to or subtracted V2(r2, θ2),Vi(ri, θi), OV1 = r1, OV2 = r2, from angle θ1, depending on the direction of the V1V2 = d, V1Vi = di, 6 V1OO’ = θ1, 6 V2OO’ edge d, determined previously. = θ2, 6 V1OV2 = ∆θ Find: ri, θi = ? 3.3.2 Updating object position

Polar coordinate system ϴt2 C’’1 ϴt2 with a reference point O ϴt1 ϴt1 ϴ Ctx(rtx, ϴtx), position of the O t0 γ O’ ϴt0 O’ t2 O object at time x βt2 α C’t2 rt2 rt2 OCtx = rtx, object’s r coordinate at time x Ct2 βt1 βt2 rt1 rt1 γ t1 γt2 C’’0C’’1, of the α rt0 γ t1 object’s movement rt0 C’t1 βt1 Ct1 Ct2 α trajectory α C’t1 C’’1 ∠CtxOO’ = ϴtx, object’s β C’t2 γ Ct1 coordinate at time x t0 γ C’t0 βt0 t0 α ∠OCtxC’tx = βtx, angle of C’’0 α C’t0 βt0 rotation at time x Ct0 ∠OCtxC’’1 = γtx, direction of Ct0 movement at time x ∠C’’1CtxC’tx = α, orientation C’’0 with respect to geodesic (a) (b) Figure 13: Movement of the object along a hyperbolic in Spherical (a) and Hyperbolic (b) space. Orienta- tion with respect to the geodesic is kept the same (angle α is constant) if the object is not rotating. Key: O, reference point of the global coordinate system with coordinates (0, 0); Ctx, position of the object with coordinates (rtx, θtx) and origin of the local coordinate system of the object at time x; βtx, object’s angle of rotation in local coordinates at time x; α, angle between the geodesic and the object’s local reference direction (should not change if the object doesn’t rotate); γtx, direction of object’s velocity vector

7 Note: In addition to updating the global po- sition vector of an object, the velocity vector and α = βt0 − γt0. Angle α is the difference be- rotation angle have to be updated accordingly in tween object rotation and its geodesic of movement order to keep their orientation towards the geodesic (C”0C”1), which has to stay constant if the object consistent (for a non rotating object; for a rotating is not rotating over time. Hence: object, extra rotation over time should be added βt1 = γt1 + α (25) after the position of the object was recalculated). γ0 and γ are supplementary angles, so: Corollary 4 Given: O(0, 0),Ct0(rt0, θt0), t1 t1 Ct1(rt1, θt1), OCt0 = rt0,Ct0Ct1 = rp, 6 Ct0OO’ 0 γt1 = Π − γt1 (26) = θt0, 6 OCt0C” = γt0, 6 OCt0C’t0 = βt0 Find: rt1, θt1, γt1, βt1 = ? To find the θ coordinate, either subtract or add γt0 should be in the range 0 to π, take exple- ∆θ to the θc depending on whether the angle α or mentary angle if α0 > π. This will determine the direction of the movement with respect to the refer- its explementary angle is used for the subsequent calculation. ence point (needed to calculate θt1). 6 0 Let OCt1Ct0 = γt1 If K > 0, then: 4 Results rt1 = arccos cos rt0 cos rp + sin rt0 (19) sin rp cos α 4.1 Engine cos r − cos r cos r ∆θ = arccos p t0 t1 (20) Using the method described in the previous sec- sin rt0 sin rt1 tion and OpenGL, we have created an engine that 0 cos rt0 − cos rp cos rt1 has a capability to calculate the objects and ren- γt1 = arccos (21) sin rp sin rt1 der the vector graphics in a non-Euclidean space with constant arbitrary curvature in the range of If K < 0, then: −1 ≤ K ≤ 1. rt1 = arccos cosh rt0 cosh rp + sinh rt0 The movement of an object can be shown dy- (22) sinh rp cos α namically by creating several time-lapse images col- lated from multiple screenshots of the game screen cosh r cosh r − cosh r ∆θ = arccos t0 t1 p (23) one over the other. These are shown in the figures sinh rt0 sinh rt1 14 and 15 below. They show movement through

0 cosh rp cosh rt1 − cosh rt0 different geodesics at K = 1 and K = −1 on the γt1 = arccos (24) sinh rp sinh rt1 left and right of each figure respectively.

(a) Spherical space (K = 1) (b) Hyperbolic space (K = −1) Figure 14: Movement along the geodesic orthogonal to the 0o theta vector

8 (a) Spherical space (K = 1) (b) Hyperbolic space (K = −1) Figure 15: Movement along the geodesic at 45o to the 0o theta vector While these timeline images have the same start- order to keep objects within the boundaries of the ing position of the object, these have been used as screen. This way they can be more easily observed. an aid for visual comparison between images. The Because of the coordinate system used, it is easy to software can calculate the object flying in arbitrary set or lift this limiting distance: the object’s theta direction with arbitrary speed as well as starting coordinate is increased by π and then standardised. from arbitrary position in the space. This makes it appear on the antipodal point of the Another feature that was added to aid demon- limit circle with preserved velocity and orientation. stration of the space is the cut-off of the worlds at a This can be seen in Figure 14 (b) and Figure 15 distance of N pixels. This can be seen in the hyper- (b). As the object crosses into the shaded area of bolic movement time-lapse image. While the hyper- the world, it is immediately reset on the antipodal bolic space should be infinite, we chose to limit it in point of the white limit circle.

(a) Spherical space (K = 1) (b) Hyperbolic space (K = −1) Figure 16: Rotation of the object around its centre point

9 In addition to movement through curved space be used to explain the concept of curvature much we decided to show a time-lapse image of a rotation more easily than the standard methods of imagining of the ‘’ (in this case, the we describe a square the spherical space or a flat projection of a sphere. by a that has 4 vertices equidistant We created a video [9] displaying the implemen- from the centre of the object in local coordinates as tation. well as being equally spaced out around the local reference point). Figure 16 shows a rotation of this 4.2 Complexity Analysis object in spherical (a) and hyperbolic (b) space. Please note that the object is described with ex- The complexity of the method can be calculated actly the same parameters in hyperbolic and spher- by examining its components individually and then π 3π 5π 7π combining to find the overall complexity. ical spaces: [(90, 8 ), (90, 8 ), (90, 8 ), (90, 8 )] Note that the grid-lines in the time-lapse images Shape rendering is the more computationally have been created and rendered as separate game and spatially expensive part of the method. In or- objects, hence there is no need to recalculate them der to find all of the required points to display one manually when the curvature changes. shape correctly, positions of each vertex need to be The curvature of the world can be changed in calculated, which requires O(v) time, where v is real time using keyboard inputs in a similar man- the number of vertices. Subsequently, intermedi- ner to controlling the object’s acceleration and ori- ate points on each edge have to also be computed, entation. The curvature can be set to several pre- requiring O(i) time to find all of the points on a made values or changed continuously by adding or single edge, where i is the level of tessellation. So subtracting a small number from the current curva- overall complexity to render the world with s num- ture variable every time the corresponding button ber of shapes would be O(s ∗ v ∗ i). The best case is pressed. would be equal to O(n) complexity, if two of the terms are negligibly small (e.g. a world with small number of 2 vertex shapes). The worst case can be approximated to O(n3) if all terms were com- parably large (e.g. rendering a world with a large number of shapes with many vertices, like circles). Spatial complexity for shape rendering is only O(v∗i) as, while all of the vertices have to be stored in the memory between calculating and rendering a shape, these are then rewritten to store the next shape’s data. So either O(n) in the best case or O(n2) in the worst case. Regarding object’s movement calculation, only one calculation per object is required and the previ- ous position record is overwritten, both spatial and time complexity is O(n), where n is the number of objects in the world that are being updated. Additional cost comes from the use of trigono- metric and hyperbolic functions in the calculations. These operations are slower to compute than sim- Figure 17: Movement of the object while changing pler operations (the exact cost of these functions the curvature from K=-1 to K=1 depends on the hardware being used). For example some systems use the AGM iteration [10] method to In the time-lapse image above (Figure 17) this compute elementary functions (including trigono- feature is demonstrated by starting the object’s metric functions), which is faster than the previ- movement in hyperbolic space and then gradually ously common Taylor series method. increasing the value of K in order to progress from a hyperbolic space through flat space and into a spherical space. This can be observed by not only 5 Discussion the movement of the ‘spaceship’ (i.e. red shape), but also the change in the way the grid lines are Overall the implementation of the method has good curved. performance up to a certain number of objects or This feature allows for flexibility in the use of the amount of tessellation. For the first implemen- the engine. The gradual change in curvature can tation we have been focussing on making sure the

10 method was implemented correctly and was work- in Astrophysics and Cosmology, specifically in mod- ing continuously under any curvature in the range elling the different dynamic systems of cosmologi- −1 ≤ K ≤ 1. This has been achieved and the next cal objects. For this, the engine would have to be step is to build upon this implementation to achieve modified in order to have a capability of calculating a more complete engine. There are several ways this non-uniform curvature of space-time. [15] [16] But method could be improved and expanded upon. once completed, the ability to dynamically change Our initial extension would be the implemen- the global curvature would provide an opportunity tation of parallelism. Calculating all the points in to test how the objects would be expected to behave order to render the objects creates a bottleneck is- in positively or negatively curved space-time. sue. This could be parallelised to achieve a time complexity of the order O(n), where n is the num- ber of objects in the world. Performing some of the 6 Conclusion calculations directly on the GPU would be one of We were aiming to create a physics and graphics such solutions. engine capable of calculating the shapes, positions With regards to reducing the additional compu- and movement of objects in a 2D space with con- tational cost of trigonometric functions, several ap- stant positive or negative curvature; and then ren- proaches can be taken here. One of the commonly der these objects onto the screen using vector graph- used methods would be to use lookup tables: pre- ics. Another feature we were aiming to implement calculating a table of values for all of the angles in was the ability to change the curvature in real-time order to just lookup the result instead of performing while the application was running. the calculation when called. This is a widely used We have achieved both of these objectives by approach, for example, Frank Rochet’s implemen- creating a method of calculating all of the points tation [11] completely replaces the standard C++ necessary to render the objects. This method is us- trigonometry functions with custom functions that ing spherical and hyperbolic trigonometry as well as use lookup tables. Another way to reduce the cost a polar coordinate system to calculate the motion of the trigonometric functions would be to replace of the object along a geodesic through curved space some of the calculations that include them with al- and subsequently to find the positions of every ver- ternative approaches. tex of the object given its position and shape in lo- There are also ways to expand on this method in cal coordinates. After that intermediate points are order for this engine to perform different operations. found in-between the vertices in order to render the These could range from a collision detection sys- curved lines onto the screen using. The additional tem to Artificial intelligence algorithms, and from objective of having a real-time modification of the texturing of the objects (instead of simple vector curvature was achieved by having a dynamic recal- graphics) to having a non-uniform curvature in the culation of the objects at every step of the appli- world. These are some of the improvements we are cation execution. This method is currently capable planning to implement to make a more complete of supporting multiple objects as well as a real-time graphics and physics engine. control of one of the objects using the keyboard in- There are multiple potential applications for this puts, which can be seen in Figure 1. Currently all engine. The obvious one is using it for educa- of the calculations are done sequentially, which cre- tional purposes, due to this representation of non- ates a bottleneck that can slow down the frame rate Euclidean space being more intuitive than standard of the application if there are a large number of ob- projections used: Poincare disk and Upper Half- jects that need to be rendered. This is not a critical Plane models, as such it could be a good introduc- problem, because there are several solutions that we tion to the concepts on non-Euclidean geometry. are planning to research, such as parallelisation of A different use for the engine could be in car- the calculations. tography. [12] The engine could be modified to ef- The ability to change the curvature dynamically ficiently convert the cartographic data into differ- allows for a more intuitive representation of the ent projections beyond just Azimuthal Equidistant. non-Euclidean space, because the observer can see The dynamic modification of curvature could also how the object changes in real-time as the curva- be utilised as a zooming feature from a global to ture is increased or decreased. This also bridges the a more localised map. There is also research be- gap between the study of spherical and hyperbolic ing done on the use of non-Euclidean geometry in geometries, as both are rendered using the same ecology [13] and climatology [14], where this engine method with the same projection. Hence the possi- could help with modelling dynamic systems in non- bility of its application in multiple fields: cartogra- Euclidean environment. phy, education, physics, among others. Another use for the planned 3D engine could be

11 References

[1] T. L. Heath, Euclid’s Elements. Dover, 1956. (translated). [2] C. A. Furuti, “Visualizations of the azimuthal orthographic geometry,” 2012 (accessed August 02, 2018). http://www.progonos.com/furuti/MapProj/Dither/CartHow/HowOrtho/Img/im orthoRays.pngl. [3] Tamfang, “Equilateral triangles,” 2011 (accessed August 03, 2018). https://pointatinfinityblog.files.wordpress.com/2018/02/triangle5.png?w=480&h=480.

[4] I. Todhunter, For the use of colleges and schools. Project Gutenberg License, 1886. (republished November 12, 2006). [5] H. S. Carslaw, The Elements of Non-Euclidean Plane Geometry and Trigonometry. Longmans, Green and co., 1916.

[6] T. Traver, “Trigonometry in the hyperbolic plane,” 2014 (accessed December 2017). Manuscript. [7] W. Gellert, S. Gottwald, M. Hellwich, H. Kstner, and H. Kstner, The VNR Concise Encyclopedia of Mathematics, 2nd ed. Van Nostrand Reinhold: New York, 1989. ch. 12. [8] J. Gray, Non-euclidean geometryA re-interpretation. Historia Mathematica, 1979. 236258.

[9] D. Osudin, C. Child, and Y. Hui-He, “Rendering non-euclidean space in real-time using spherical and hyperbolic trigonometry,” 2019. https://youtu.be/A1ZCFh5qfNg. [10] R. P. Brent, “Multiple-precision zero-finding methods and the complexity of elementary function evaluation,” 2010 (accessed August 26, 2018). http://arxiv.org/abs/1004.3412v2.

[11] F. Rochet, “Fast trigonometry functions using lookup tables,” 2004 (accessed August 30, 2018). http://www.flipcode.com/archives/Fast Trigonometry Functions Using Lookup Tables.shtml. [12] G. Gartner and H. Huang, “Recent research developments in modern cartography in europe,” Issue 1: EuroCarto 2015, 2015. [13] C. Sutherland, “Modelling noneuclidean movement and landscape connectivity in highly structured ecological networks,” British Ecological Society, 2014. [14] C. Frei, “Interpolation of temperature in a mountainous region using nonlinear profiles and noneu- clidean distances,” Royal Meteorological Society, 2013. [15] K. L. Ross, “The ontology and cosmology of non-euclidean geometry,” Friesian School, 2001.

[16] H. Kragh, “Geometry and astronomy: Pre-einstein speculations of non-euclidean space,” Aarhus University, 2012.

12