Reputation: 221
I need to define a cube and three intervals Cx, Cy, and Cz as the projections of the cuboid on the x-, y-, and z-axes, respectively. I'm supposed to use the interval predicate interval_dur
. The image on the link may more clear what i need indeed.
The original question goes like this:
We can define three-dimensional qualitative spatial relations between cuboids such as inside and on top of by considering the qualitative relations between their projections on each axis. Figure 1 shows cuboid
C
with interval projections on the x-, y-, and z-axes. (a) Define a cuboidC
. Define three intervalsCx
,Cy
, andCz
as the projections of the cuboid on the x-, y-, and z-axes, respectively. Use the interval predicateinterval_dur
.
Upvotes: 0
Views: 342
Reputation: 60034
By sure this answer could be off topic, but since you tagged SWI-Prolog your question, I will show an extension that have been made available in version 7.1: dicts.
:- module(cuboid, []).
M.cx() := Cx :- Cx is M.x2 - M.x1 .
M.cy() := Cy :- Cy is M.y2 - M.y1 .
M.cz() := Cz :- Cz is M.z2 - M.z1 .
M.volume() := V :- V is M.cx() * M.cy() * M.cz().
M.scale(F) := cuboid{x1:X1, x2:X2, y1:Y1, y2:Y2, z1:Z1, z2:Z2} :-
maplist(mult(F, M), [x1,x2, y1,y2, z1,z2], [X1,X2, Y1,Y2, Z1,Z2]).
mult(F, M, A, V) :- V is M.A * F.
here is an example of use
1 ?- C = cuboid{x1:1, x2:2, y1:1, y2:2, z1:1, z2:2}, writeln(C.volume()).
1
C = cuboid{x1:1, x2:2, y1:1, y2:2, z1:1, z2:2}.
2 ?- S = $C.scale(3), Vs = S.volume().
S = cuboid{x1:3, x2:6, y1:3, y2:6, z1:3, z2:6},
Vs = 27.
I have little clue about spatial relations
or qualitative relations
you are looking for. I imagine that will be a set of spatial relations between two cuboids, like
intersect, is_on_top, is_at_left, etc...
Depending on the applicative domain you are supposed to handle, consider using a constraint library. library(clpr) for reals, library(clpq) for rationals, or library(clpfd) for integers.
This last one is more developed, and actively mantained.
Upvotes: 0
Reputation: 7229
My understanding of the question: you need to create a predicate interval_dur(C, Cx, Cy, Cz) such that "cuboid" C and intervals Cx, Cy, Cz are related in a specified way.
"C" can be specified using three points, so the whole predicate could be something like this:
interval_dur(C, Cx, Cy, Cz) :-
C = ((X1, Y1, Z1), (X2, Y2, _Z2), (_X3, _Y3, Z3)),
Cx = (X1, X2),
Cy = (Y1, Y2),
Cz = (Z1, Z3).
This formulation assumes that points in C are in a specific order: the most close bottom left first, etc. This can be improved using sorting.
Upvotes: 0