I failed geometry - need some coordinate help

Everything else that doesn't fall into one of the other PB categories.
chio
User
User
Posts: 30
Joined: Thu Jun 24, 2004 1:55 pm
Location: New York City
Contact:

I failed geometry - need some coordinate help

Post 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?

Image

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,
chio
filperj
User
User
Posts: 77
Joined: Tue Sep 16, 2003 8:53 pm
Location: Nevers(France)

Post 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
chio
User
User
Posts: 30
Joined: Thu Jun 24, 2004 1:55 pm
Location: New York City
Contact:

Post 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". :D
User avatar
GeoTrail
Addict
Addict
Posts: 2794
Joined: Fri Feb 13, 2004 12:45 am
Location: Bergen, Norway
Contact:

Post by GeoTrail »

chio wrote:Now I know the answer to when I asked my self in highschool, "why do I need to take geometry". :D
Hehehehe been there done that, know how you feel :lol:
I Stepped On A Cornflake!!! Now I'm A Cereal Killer!
filperj
User
User
Posts: 77
Joined: Tue Sep 16, 2003 8:53 pm
Location: Nevers(France)

Post 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

chio
User
User
Posts: 30
Joined: Thu Jun 24, 2004 1:55 pm
Location: New York City
Contact:

Post 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.
chio
filperj
User
User
Posts: 77
Joined: Tue Sep 16, 2003 8:53 pm
Location: Nevers(France)

Post by filperj »

8)
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 :oops: , I don't know if this is really understandable)
chio
User
User
Posts: 30
Joined: Thu Jun 24, 2004 1:55 pm
Location: New York City
Contact:

the formula

Post by chio »

Oh I can see the formula I just can't make it work! :D 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,
Post Reply