Page 2 of 2
Re: Plot GPS positions over an image
Posted: Mon Apr 22, 2013 11:50 am
by dave_probertGA6e24
Hi Nakia,
Ok, this might be a little long-winded, but it hopefully shows the process better.
I took your original code (from your last post) and used it to create the mouse location function.
Your function does basically this - (for x values) where qx is the plot point, vx is the incoming NE coord, cx is the orig, sx is the scale factor and ox is the offset.
That gives us these equations:
qx = ((vx - cx) * sx) + ox
qy = ((cy - vy) * sy) - oy
Reworking these equations to use qx as the mouse loc and getting vx out (for the NE coord):
qx - ox = (vx - cx) * sx
. (qx - ox) / sx = vx - cx
. ( (qx-ox) / sx ) + cx = vx
and (. at the start of the line means "is the same as"):
qy + oy = (cy - vy) * sy
. (qy + oy) / sy = cy - vy
. (qy + oy) / sy = -vy + cy
. -(((qy + oy) / sy) - cy) = vy
Gives us:
Code: Select all
vx = ( (mouseX - tXOffset) / GXFactor) + tXOrig
vy = (( (mouseY + tYOffset) / GYFactor) - tYOrig) * -1
or
put ( (mouseX - tXOffset) / GXFactor) + tXOrig into vx
put (( (mouseY + tYOffset) / GYFactor) - tYOrig) * -1 into vy
Looking at your code you might want to adjust the GYFactor to be negative so that you are only then adding values. This would give more consistency in the code and get rid of the nasty * -1 in the last line above. In theory both the X and Y calculations should use the same structure - you just scale into the other quadrant (i.e. scale by -GYFactor will give an upside down value - which I think is what you want)
In most cases you will find that just playing with the equations will give you the results - then it's just a case of wrapping them into code.
Hope that helps again,
Dave
Re: Plot GPS positions over an image
Posted: Tue Apr 23, 2013 12:21 am
by Nakia
Dave,
Firstly let me thank you for all your help.
I will get back to this tonight and see how the changes you suggested work.
Thanks again
Re: Plot GPS positions over an image
Posted: Fri May 03, 2013 4:51 am
by Nakia
Back looking for help again..
After implementing your fucntion above it has highlighted that I still have an issue with the Plotting Algorithm, I never thought I would have so mouch trouble with this.
Any way, I am certian it is because of the difference in conventions between LC and Easting and Northings in terms of the screen etc.
I have been staring at the screen all afternoon trying multiple permatations of the code I posted on the last page and seem to be getting no where.
The issue is coming from having to Plot "Down to Up" meaning that as Northing's rise the Plotted Point will rise on the screen but LC Convetion has the the Y Axis working opposite.
I know this is a simple math problem but for the life of me I just cant figure it out.
Does anyone have any suggestions?
Re: Plot GPS positions over an image
Posted: Fri May 03, 2013 7:33 am
by Nakia
So I have modified it a bit and have got to here.
What I have changed is I have made the Y Axis work the same as the X Axis (Subtract Coord Value from Origin Point " Origin Point for Y is now the lower Number, same theory as X")
So theoretically this part should work but the thing I cant get to work from here is how to calculate the Plot point as this number needs to be calculated in reverse.
I.e. the starting point will be the bottom of the image
Gee I hope this makes sense?
Code: Select all
put line 4 of gPrefs into tXOrig
put line 5 of gPrefs into tYOrig
set the itemdel to comma
put item 1 of the rect of img "imageHolder" into tXOffset
put item 4 of the rect of img "imageHolder" into tYOffset
## Now we should be able to plot an Event
set the itemdel to tab
repeat with x = 1 to the number of lines in lValidEvents
## Calculate the LOC
put (item 25 of line x of lValidEvents - tXOrig) * GXFactor into tXLoc
add tXOffset to tXLoc
put (item 26 of line x of lValidEvents - tYOrig) * GYFactor into tYLoc
put (tYOffset - tYLoc) into tYLoc
Re: Plot GPS positions over an image
Posted: Fri May 03, 2013 10:04 am
by bn
Nakia,
from what I understand is you want to plot into a given area values that have bottomLeft as their 0,0 coordinate as opposed the Livecode that uses topLeft of the card as 0,0
I made a little stack that simulates data that is in bottomLeft 0,0 of given area format and is transformed into LiveCode format.
You have to use the height of the display rectangle to invert your Y values.
I hope I got your problem right.
Kind regards
Bernd
Re: Plot GPS positions over an image
Posted: Fri May 03, 2013 11:39 am
by dave_probertGA6e24
Hi Nakia,
I too have made a little stack which might help a little with your problem.
You can enter the North and East settings and have a play. Try various values from your actual datasets and see what happens. You will probably want to drop in an actual map in place of the dummy I used, and adjust the locations of the input boxes - everything is calculated - so there should be no need to hardcode any values.
All the code is on the Card level script (the buttons only call handlers in there) - The mousemove handler over the image you might need to copy to another image if you import one - it's only a single line calling a handler in the script.
Let me know if it works for you (or not!)
Cheers,
Dave
Re: Plot GPS positions over an image
Posted: Fri May 03, 2013 12:16 pm
by bn
Hi Dave,
that is a very nice stack.
You might want to add
Code: Select all
on preOpenCard
initScaling
pass preOpenCard
end preOpenCard
otherwise it goes right into the debugger because on opening the stack the globals are not yet initialized. It crashed LC once.
Kind regards
Bernd
Re: Plot GPS positions over an image
Posted: Fri May 03, 2013 1:21 pm
by dave_probertGA6e24
Good catch Bernd,
Ooops, I forgot to mention that you need to click the "initScaling" button
first. I was in a bit of a hurry.
I'll add that to the stack here, but I'll wait for Nakia to have a look before uploading any changes. Then I can add other stuff too
Cheers,
Dave
Re: Plot GPS positions over an image
Posted: Sun May 05, 2013 11:52 pm
by Nakia
Thankyou both for the helper Stacks, and the best news is it was able to show me where I was going wrong!!
I was not calculating the YScaleFactor into a negative number which caused all the issues..
Thankyou both so much for your help with this...