update
[fp1415-soccerfun.git] / src / Game / Geometry.dcl
1 definition module Geometry
2
3 /** This module defines the part of the SoccerFun API that is concerned with the footballer dimensions.
4 */
5 import StdEnvExt
6
7
8 class scale a :: !Real !a -> a
9
10
11 :: Metre
12 m :: !Real -> Metre // (m metre) is a distance in metres
13
14 instance zero Metre
15 instance + Metre
16 instance - Metre
17 instance abs Metre
18 instance sign Metre
19 instance ~ Metre
20 instance == Metre
21 instance < Metre
22 instance toReal Metre
23 instance toString Metre
24 instance scale Metre
25
26
27 :: Position
28 = { px :: !Metre // x-coordinate in plane
29 , py :: !Metre // y-coordinate in plane
30 }
31 :: Position3D
32 = { pxy :: !Position // position on plane
33 , pz :: !Metre // height above plane
34 }
35
36 instance zero Position
37 instance zero Position3D
38 instance == Position
39 instance == Position3D
40 instance toString Position
41 instance toString Position3D
42
43 class toPosition a :: !a -> Position
44 class fromPosition a :: !Position -> a
45 class toPosition3D a :: !a -> Position3D
46 class fromPosition3D a :: !Position3D -> a
47 instance toPosition (!Metre,!Metre)
48 instance toPosition Position
49 instance toPosition Position3D
50 instance fromPosition (!Metre,!Metre)
51 instance fromPosition Position
52 instance fromPosition Position3D
53 instance toPosition3D (!Metre,!Metre,!Metre)
54 instance toPosition3D Position
55 instance toPosition3D Position3D
56 instance fromPosition3D (!Metre,!Metre,!Metre)
57 instance fromPosition3D Position
58 instance fromPosition3D Position3D
59
60 dist :: !a !b -> Metre | toPosition3D a & toPosition3D b
61
62
63 :: Angle
64
65 pi :== 3.1415926535897932384 // (rad pi) is equivalant with (degree 180)
66
67 rad :: !Real -> Angle // (rad x) is an angle of x radians (counter-clockwise)
68 degree :: !Int -> Angle // (degree x) is an angle of x degrees (counter-clockwise)
69
70 instance zero Angle
71 instance + Angle
72 instance - Angle
73 instance abs Angle
74 instance sign Angle
75 instance ~ Angle
76 instance == Angle
77 instance < Angle
78 instance toReal Angle
79 instance toInt Angle
80 instance toString Angle
81 instance scale Angle
82 instance sinus Angle
83 instance cosinus Angle
84 instance tangens Angle
85 instance arcsinus Angle
86 instance arccosinus Angle
87 instance arctangens Angle
88
89 /** orthogonal a
90 returns the left- and right- orthogonal angles to a
91 */
92 orthogonal :: !Angle -> (!Angle,!Angle)
93
94 /** bearing nose base target:
95 returns the smallest rotation angle needed for a player at @base having current direction @nose
96 to face @target.
97 The result is a value between ~pi and pi.
98 */
99 bearing :: !Angle !base !target -> Angle | toPosition base & toPosition target
100
101
102 :: RVector
103 = { dx :: !Metre // difference in px-coordinate
104 , dy :: !Metre // difference in py-coordinate
105 }
106 :: RVector3D
107 = { dxy :: !RVector
108 , dz :: !Metre
109 }
110
111 class toRVector a :: !a -> RVector
112 instance toRVector Angle
113 instance toRVector Position
114
115 /** size_vector {dx, dy} = sqrt ( dx^2 + dy^2)
116 size_vector3D {dxy,dz} = sqrt (dxy.dx^2 + dxy.dy^2 + dz^2)
117 */
118 size_vector :: !RVector -> Metre
119 size_vector3D :: !RVector3D -> Metre
120
121 instance + RVector
122 instance + RVector3D
123 instance - RVector
124 instance - RVector3D
125 instance zero RVector
126 instance zero RVector3D
127 instance one RVector
128 instance one RVector3D
129 instance ~ RVector
130 instance ~ RVector3D
131 instance scale RVector
132 instance scale RVector3D
133
134
135 /** move_point v p:
136 moves point p over vector v.
137 move_point3D v p:
138 moves point p over vector v.
139 */
140 move_point :: !RVector !Position -> Position
141 move_point3D :: !RVector3D !Position3D -> Position3D
142
143 /** repell minimum_distance base pos:
144 if @pos is too close to @base, compute a new position that is at least @minimum_distance metres away from @base.
145 attract maximum_distance base pos:
146 if @pos is too far away from @base, compute a new position that is at most @maximum_distance metres away from @base.
147 */
148 repell :: !Metre !Position !Position -> Position
149 attract :: !Metre !Position !Position -> Position
150
151 /** point_to_rectangle (a,b) c
152 returns c if (point_in_rectangle (a,b) c) and the projected point c` of c that is exactly on the closest edge of
153 rectangle (a,b).
154 */
155 point_to_rectangle :: !(!Position,!Position) !Position -> Position
156
157 /** point_in_rectangle (a,b) c
158 returns True iff point c is inside the rectangle determined by
159 the diagonal corner points a and b.
160 */
161 point_in_rectangle :: !(!Position,!Position) !Position -> Bool
162
163
164 :: Velocity
165
166 ms :: !Real -> Velocity // (ms metre-per-second) is a velocity
167
168 instance zero Velocity
169 instance + Velocity
170 instance - Velocity
171 instance abs Velocity
172 instance sign Velocity
173 instance ~ Velocity
174 instance == Velocity
175 instance < Velocity
176 instance toReal Velocity
177 instance toString Velocity
178 instance scale Velocity
179
180
181 :: Speed // speed of an object
182 = { direction :: !Angle // direction of object
183 , velocity :: !Velocity // velocity of object
184 }
185 :: Speed3D // speed of an object in space
186 = { vxy :: !Speed // surface speed of object
187 , vz :: !Velocity // velocity in z-axis (positive: goes up; negative: goes down; zero: horizontally)
188 }
189
190 instance zero Speed
191 instance zero Speed3D
192 instance == Speed
193 instance == Speed3D
194 instance toString Speed
195 instance toString Speed3D
196
197 class toSpeed a :: !a -> Speed
198 class fromSpeed a :: !Speed -> a
199 class toSpeed3D a :: !a -> Speed3D
200 class fromSpeed3D a :: !Speed3D -> a
201
202 instance toSpeed Speed3D
203 instance fromSpeed Speed3D
204 instance toSpeed3D Speed
205 instance fromSpeed3D Speed