Radiation Dose Map - problem!

Post Reply
Posts: 19
Joined: Mon Jan 21, 2019 9:27 pm
My devices: iPhone SE
Flag: Great Britain

Radiation Dose Map - problem!

Post by PaulKnight »

Hi everyone.

I have been playing around with SB to try and get used to some of its features, and have been having fun in the process, which I guess is the main objective! I have written some messy code which I am having some problems with. I'll try and explain!

Basically, the code randomly picks a locations for 2 radioactive sources. It then scans from top to bottom of the screen, calculating the activity/dose that would be observed at each point over an area of 400 x 500 pixels, and creates what I am calling a "dose map". An example of this is shown below.
IMG_DF24B0C7DA1A-1.jpeg (118.26 KiB) Viewed 1898 times
Once the dose map has been generated, I save it to "dosemap.jpg" - this saves me from having to redraw it through calculation later.

The programme then generates a cursor (rectangle) controlled by 4 movement boxes (left, right, up and down) to allow the user to "walk" over the dose map. The code then calculates the dose at the cursor position and displays the combined dose.

However, there is a problem!

When you move the cursor over the radiation "hot spots", you'd expect to get the highest dose rate. However, this is not the case. You actually get the highest rate at what appears to be twice the x and y position that you'd expect. You can see this by moving the cursor to the right and below a hotspot, assuming its been randomly generated sufficiently close to x=0 and y=0 to allow you to move the cursor far enough away!

I think I have the maths code correct, but wondered if there was a problem with my saving and pasting of the radiation map.
I'm a little confused.

Any thoughts very much appreciated.

All the best,

Oh, and to exit the program once its running, tap the far right and bottom of the screen!

graphics clear 1,1,1
refresh on
set toolbar off

' Choose random location for radiation source 1

' Choose random location for radiation source 2

draw color 0,0,0


' use Pythag theory to calculate the distance from the x,y position to source 1

' use Pythag theory to calculate the distance from the x,y position to source 2

' prevents a divide by 0 error
if shinepath1=0 then
end if

' prevents a divide by 0 error
if shinepath2=0 then
end if

' calculate the dose from source 1 and source 2, based on inverse square law

' total dose at position x,y is the sum of the dose from each source

' Determine what colour to plot the total dose, depending on its magnitude
if dosetotal >0 and dosetotal=<50 then
draw color 0,0,0

if dosetotal >50 and dosetotal=<100 then
draw color 1,0.2,0.2

if dosetotal >100 and dosetotal=<150 then
draw color 1,0.4,0.4

if dosetotal >150 and dosetotal=<200 then
draw color 1,0.6,0.6

if dosetotal>200 and dosetotal=<250 then
draw color 1,0.7,0.7

if dosetotal>250 and dosetotal=<300 then
draw color 1,0.8,0.8

' draw the dose at position x,y
draw pixel x,y

' once 500 lines in the Y axis has been reach move onto the section of code that allows the cursor to be moved around the zone
if y>500 then
goto survey

' increment x until 400 pixels has been reached, then increment Y value
if x>400 then
end if

' continue scanning the whole area
goto loop

' this section of code allows the user to move a cursor around the area to determine the dose at each point
' save the "dose map" to an image. This prevents having to rec-calculate the dose map each time the cursor is moved
graphics save 0,0,200,250 to "dosemap.jpg"

' draw 4 buttons to allow the user to move a cursor around the area
fill color 0,0.5,0.5
fill rect 100,250 to 150,300
fill rect 150,330 to 200,380
fill rect 50,330 to 100,380
fill rect 100,410 to 150,460

' draw the dose map to the screen
draw image "dosemap.jpg" at 0,0 scale 1 angle 0

' see which direction button has been pressed by the user

GET TOUCH 0 AS xx,yy
if xx=> 100 and xx=<150 and yy=>250 and yy=<300 then cursy=cursy-1
if xx=>150 and xx=<200 and yy=>330 and yy=<380 then cursx=cursx+1
if xx=>50 and xx=<100 and yy=>330 and yy=<380 then cursx=cursx-1
if xx=>100 and xx=<150 and yy=>410 and yy=<460 then cursy=cursy+1

' Stop the cursor from going off the edge of the dosemap
if cursx>=190 then cursx=190
if cursx<=0 then cursx=0
if cursy>=240 then cursy=240
if cursy<=0 then cursy=0

' exit if screen touch on far right of screen
if xx=>300 and yy=>440 then end

'calculate the dose at the cursor location


if ashinepath1=0 then
end if

if ashinepath2=0 then
end if


' draw cursor
fill color 0,1,0
fill rect cursx,cursy to cursx+10,cursy+10

refresh on
fill color 1,1,1
fill rect 20,490 to 200,510
draw text dosetotalatcurs at 20,495
goto cursmove

User avatar
Posts: 1337
Joined: Sun May 31, 2015 12:11 am
My devices: iPhone 11 Pro Max
iPad Pro 11
Dell Inspiron laptop
CHUWI Plus 10 convertible Windows/Android tablet
Location: Calgary, Canada
Flag: Canada

Re: Radiation Dose Map - problem!

Post by rbytes »

I notice that you use pixels to draw the map. That would account for a 2:1 error ratio, because when you DRAW PIXEL at say, x=500,y=500, that is equivalent to drawing with any other draw command at 250,250.

Smart Basic measures the screen in points. So when your iPad runs GET SCREEN SIZE sw, sh, the results are sw=1024 and sh=768. But there are 2048 pixels horizontally and 1536 vertically. Think of each point being 2 pixels wide and 2 high.

Perhaps correcting for this discrepancy will give you the correct answers.

Another way you could read radiation is to GET PIXEL x,y COLOR r,g,b,a and use the resulting color to look up a table of radiation values. Just remember that since you are using a pixel command, you will have to multiply the x,y of the cursor by 2 each to get the correct pixel location.
The only thing that gets me down is gravity...

Posts: 19
Joined: Mon Jan 21, 2019 9:27 pm
My devices: iPhone SE
Flag: Great Britain

Re: Radiation Dose Map - problem!

Post by PaulKnight »

Thanks rbytes,

That sounds like a good explanation. I'll have a look to see if that will fix things.

I did consider the read pixel option, but given that the data is already quantized during the colourisation process, I would be loosing too much information going that route. Good to have options though!

Thanks again :-)

Post Reply