Page 1 of 1
					
				I failed geometry - need some coordinate help
				Posted: Sat Apr 16, 2005 9:13 pm
				by chio
				Ok, another project I am trying to play with is the idea of projecting coordinates. 
Lets say I have a mouse tablet that is a parallelogram and I wish to make sure that when my pen is on top of the top right, so is my cursor in my screen. Of course the top is larger than the bottom so therefore I can not use the same ratio formula as for the bottom or the middle. 
Has anyone played with creating a way to easily convert those coordinates to actual cursor positions that make sense?
An example in this drawing: when my pen table is in the top let, the cursor is in the top left of the screen an dso on.
HELP!!!! please.
Thanks,
 
			 
			
					
				
				Posted: Sat Apr 16, 2005 10:26 pm
				by filperj
				Maybe something like:
Code: Select all
 X coordinate on destination surface = ( Xcoordinate on source surface * width of destination surface ) / width of source surface
 
			 
			
					
				
				Posted: Sat Apr 16, 2005 11:37 pm
				by chio
				X coordinate on destination surface = ( Xcoordinate on source surface * width of destination surface ) / width of source surface 
You are correct but now we need to do that for every pixel in height.
Riht now the formula is
    scrRatioX = (desktopW/mXd) // mXd is the width of the tablet at the given Y pixel, say top
    scrRatioY = (desktopH/mYd) // mYd is the tablet height
    cX = tabletX * scrRatioX
    cY = tabletY * scrRatioY
    SetCursorPos_(cX,cY)
 Now on 2 perfect rectangles this is easy, but when the top is shorter or longer, we would need to have this formula run through every Y pixel of the odd shape tablet and calculate X dependent on the Y. Now this is a huge calculation to be done on the fly.
There has to be a geometric calculation that given 4 corners (tablet) or something like that it can give you the correct position when giving it the other 4 corners (screen).
I have it semi-working with my formula, but I don't think is good enough.
I know it may have to do with triangulation, but again, I failed geometry. Now I know the answer to when I asked my self in highschool, "why do I need to take geometry".  

 
			 
			
					
				
				Posted: Sun Apr 17, 2005 12:06 am
				by GeoTrail
				chio wrote:Now I know the answer to when I asked my self in highschool, "why do I need to take geometry".  

 
Hehehehe been there done that, know how you feel  

 
			 
			
					
				
				Posted: Sun Apr 17, 2005 12:10 am
				by filperj
				Another try (to be tested):
Code: Select all
;Structure POINT  ; already defined in PB
;   x.l
;   y.l
;EndStructure
Global TabletTopWidth , TabletBottomWidth , TabletHeight
Global ScreenWidth , ScreenHeight
; initialize these globals as needed...
Procedure FillScreenCoordFromTablet(*ScreenCoord.POINT,TabletX,TabletY)
   propY.f = TabletY / TabletHeight
   linewidth = TabletTopWidth + ( TabletBottomWidth - TabletTopWidth ) * propY
   propX.f = TabletX / linewidth
   *ScreenCoord\x = propX * ScreenWidth
   *ScreenCoord\y = propY * ScreenHeight
EndProcedure
 
			 
			
					
				
				Posted: Sun Apr 17, 2005 9:04 pm
				by chio
				filperj wrote:Another try (to be tested):
Code: Select all
;Structure POINT  ; already defined in PB
;   x.l
;   y.l
;EndStructure
Global TabletTopWidth , TabletBottomWidth , TabletHeight
Global ScreenWidth , ScreenHeight
; initialize these globals as needed...
Procedure FillScreenCoordFromTablet(*ScreenCoord.POINT,TabletX,TabletY)
   propY.f = TabletY / TabletHeight
   linewidth = TabletTopWidth + ( TabletBottomWidth - TabletTopWidth ) * propY
   propX.f = TabletX / linewidth
   *ScreenCoord\x = propX * ScreenWidth
   *ScreenCoord\y = propY * ScreenHeight
EndProcedure
 
Amazing, tested and it works much better than what I had. Thanks so much. Now since the odd shape is actually inside of the rectangle of the tablet, I am adding the differences between the actual distance to the edge. I hopefully can figure that one out ok.
This was great, thanks.
 
			 
			
					
				
				Posted: Sun Apr 17, 2005 11:43 pm
				by filperj
				
 
When you don't know the formula (I don't know many), think geometry as a graphic thing, and you will see the formula... Well, maybe not the really complex ones :roll: 
(My english is poor 

 , I don't know if this is really understandable)
 
			 
			
					
				the formula
				Posted: Tue Apr 19, 2005 7:39 pm
				by chio
				Oh I can see the formula I just can't make it work!  

  oh and your english is very good.
I have to stop this project for a few weeks as work cam in, so I will post the final results soon.
Thanks a lot,