Copyright 2008 David Dodds
Computing Sense of Spatiality 2
Last time we saw a number of conditional statements for testing the
spatial relationships of pairs of objects. This was done by using the
x and y values of the SVG co-ordinates of both SVG items. Here we see
some items selected from the barchart that has been discussed before.
Below next there are some SVG statements from that barchart shown:
<text id="uplabel" x="340" y="20"
style="font-family:Verdana; font-size:12.333; fill:black">
UP
</text>
<text id="downlabel" x="340" y="230"
style="font-family:Verdana; font-size:12.333; fill:black">
DOWN
</text>
<rect id="xbaseline" x="37" y="190" width="280" height="1"
style="stroke:black; stroke-width:1" />
<rect id="endlineright" x="333" y="96" width="1" height="104"
style="stroke:black; stroke-width:1" />
<rect id="bar3" x="80" y="111" width="20" height="89"
style="stroke:blue; fill:orange; stroke-width:0" />
<text id="text1" x="37" y="210"
style="font-family:Verdana; font-size:12.333; fill:black">
95969798990001020304050607
</text>
<text id="text2" x="37" y="230"
style="font-family:Verdana; font-size:12.333; fill:blue">
Mean High Ratings August 2007
</text>
Next we look at the statements using the x and y values from text1 and
text2 as inputs.
public boolean near2( int x1, int y1, int x2, int y2 )
text1 x1=37 y1=210 text2 x2=37 y2=230 37-37=0 230-210=20 20 x 20
= 400 d=20 20<=10 false
near2 evaluates as false in this case as the radial distance
separating text1 and text2 is greater than the dist measure, dist is
10, and the separation is 20. If we programmed near2 such that one
specified the dist value in the argument list we would have a more
flexible conditional test. Conversely we could have a real function
and return the value of separation instead of true or false and do
something in the calling program according to the returned real dist
value.
public real nearTo(int x1, int y1, int x2, int y2, int k(2))
1.374549 - k(1)/k(2)
nearTo returns a real instead of true or false and in this case we see
1.374549 is the value. We still need to subtract k(1)/k(2) from that
value to get the intended measure that the routine is designed to
provide. k(1) is the x axis range of values to be considered in
mapping this nearTo value. k(2) is the slope of the function doing the
mapping, the function is a sigmoidal one. A sigmoidal function is felt
to represent how humans judge such things more closely than does a
straight line function. See Lotfi Zadeh and fuzzy set theory. nearTo
returns a real value and the calling program must decide what to do as
a result of the value of the real.
public boolean near( int x1, int y1, int x2, int y2 )
text1 x1=37 y1=210 text2 x2=37 y2=230 false
near used a dist value of 10 to decide true or false. if the function
was setup to input the dist value it would be more flexible. The
separation distance was 20, which is greater than dist=10 and so the
function returns false. ie near with separation less than or equal to
10, no. (ie false)
public boolean at( int x1, int y1, int x2, int y2 )
text1 x1=37 y1=210 text2 x2=37 y2=230 false
The X values are at but the Y values are not, hence at is false.
public boolean Below( int y1, int y2 )
text1 x1=37 y1=210 text2 x2=37 y2=230 false
Text1 is Below text2 is false.
public boolean toRight( int x1, int x2 )
text1 x1=37 y1=210 text2 x2=37 y2=230 false
Text1 is to the Right of text2 is false.
public boolean Above( int y1, int y2 )
text1 x1=37 y1=210 text2 x2=37 y2=230 true
Text1 is Above text2 is true.
public boolean toLeft( int x1, int x2 )
text1 x1=37 y1=210 text2 x2=37 y2=230 false
Text1 is to the Left of text2 is false.
public boolean sameX( int x1, int x2 )
text1 x1=37 y1=210 text2 x2=37 y2=230 true
Text1 is at the same X axis location as text2 is true.
public boolean sameY( int y1, int y2 )
text1 x1=37 y1=210 text2 x2=37 y2=230 false
Text1 is at the same Y axis location as text2 is false.
These functions all use the SVG x,y origin for the objects being
evaluated. SVG rules are that a particular corner or location on the
SVG object is used to define its origin. Also the default frame origin
for SVG is upper left corner. This means that a thing (1) which is
above another thing (2) has a LOWER Y axis value. This is
counter-intuitive for most people, the routines must be written so as
to take this into account. SVG allows one to move the frame origin
some place else, so that above things have greater Y axis values than
below things, as most people intuit. Also the routines shown last time
do not take into account the shape or morphology of the objects being
assessed. If a rectangle is one of the items being assessed then the
upper left corner of the rectangle is where its x,y orgin is. Many
people would choose to use an origin located someplace else on the
same rectangle, and since the routines have to be written to take into
account the frame origin and so on some care and thought has to be
exercised to make routines which evaluate SVG objects spatially in a
manner that is similar enough to ordinary perception.
Next episode we look at how to write routines which take all this
stuff into account. Perception is done through context.