Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Tracking mouse in abstract areas.
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Prognosis




PostPosted: Fri Oct 27, 2006 1:31 pm   Post subject: Tracking mouse in abstract areas.

How would you be able to see if your mouse was inside... saw a circle? Or a triangle? OR a random shape that was drawn on the screen.

What i acctually want to know this for, is so I can determine which quarter of the screen your mouse is in. But you see, its like a quartisian plane, but only rotated on a 45 degree angle. To make 4 large triangles.

How do I know which one my mouse is in?

Please take note I already know how to track the mouse, i just dont know how do do this.
Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: Fri Oct 27, 2006 2:08 pm   Post subject: (No subject)

How would you check if a point is inside a trianle?

Well if you break it up into 3 triangles (formed from each edge of the triangle, and the point in question), and the sum of areas of the 3 triangles == original triangle (+/- tolerance for floating point errors) then the point is inside the triangle.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Prognosis




PostPosted: Fri Oct 27, 2006 2:40 pm   Post subject: (No subject)

nah tony, that wont exactly work (i dont think at least). This is because Im working with 4 triangles on the screen with the exact same area. and I dont really know how to define these triangles.

Just picture a huge X on the screen
See how the x made four triangles
I need to know which triangle your mouse is in right now.
Clayton




PostPosted: Fri Oct 27, 2006 3:04 pm   Post subject: (No subject)

well you could come up with some sort of formula using trig, where you check to see if x is in bounds, then use some sort of trig derived formula to check between y bounds at the give x coordinate
Tony




PostPosted: Fri Oct 27, 2006 3:08 pm   Post subject: (No subject)

It might make more sense if you try to do it on paper first. Draw a trinagle, pick any arbitrary point, connect the dots.
Prognosis wrote:
and I dont really know how to define these triangles.

well the leftmost trinagle will be defined by 3 points:
0, 0
0, maxx
maxx div 2, maxy div 2


Oh yeah, and you'd have to perform the check for all 4 triangles, one at a time
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Prognosis




PostPosted: Fri Oct 27, 2006 3:13 pm   Post subject: (No subject)

Ive already tried to use trig, and it kinda failed. Obviously there must be a way to do it, but i guess i dont know how yet :/

code:
setscreen ("graphics:1000;800;position:center;center")
var xstart,ystart,reset:int
var cosangle,angle:real
reset:=0
angle:=0
loop
var xclick,yclick,x,y,buttonnumber,buttonupdown,cenx,ceny:int

const l:= 5
cenx:=500
ceny:=400

buttonwait ("down", xclick, yclick, buttonnumber, buttonupdown)
reset+= 1
if reset=49 then
reset:=0
cls
end if
x:= xclick-cenx
y:= yclick-ceny
drawfilloval (cenx,ceny,round(angle),round(angle),0)
cosangle:=x/sqrt(x**2+y**2)
angle:=arctand (sqrt ((1 - (cosangle**2)) / (cosangle**2)))
drawfilloval (cenx,ceny,round(angle),round(angle),1)
put angle
buttonnumber +=1
end loop


Sure this is close, but after 90 degrees it starts messing up.
Clayton




PostPosted: Fri Oct 27, 2006 3:49 pm   Post subject: (No subject)

ok, i have a working solution, however, im not going to give you the source, however, try to create the program to follow mine, focus on the goal, keep the extras (like the circles) out until you can get the quadrants down.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 7 Posts ]
Jump to:   


Style:  
Search: