NTNUJAVA Virtual Physics Laboratory
Enjoy the fun of physics with simulations!
Backup site http://enjoy.phy.ntnu.edu.tw/ntnujava/
November 24, 2017, 07:07:43 am *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
 
   Home   Help Search Login Register  
Never underestimate others. Never overestimate oneself. ...Wisdom
Google Bookmarks Yahoo My Web MSN Live Netscape Del.icio.us FURL Stumble Upon Delirious Ask FaceBook

Pages: [1]   Go Down
  Print  
Author Topic: how to detect a point is inside an area that is rotatable by cta ?  (Read 4369 times)
0 Members and 1 Guest are viewing this topic. Click to toggle author information(expand message area).
lookang
Hero Member
*****
Offline Offline

Posts: 1784


http://weelookang.blogspot.com


WWW
«
Embed this message
on: April 22, 2010, 04:40:39 pm » posted from:SINGAPORE,SINGAPORE,SINGAPORE

Hi everyone,

i am able to detect xCompass,yCompass inside the rectangle area with centre xMagnet,yMagnet with sizex = Magnetsizex and sizey=Magnetsizey.

Code:
if ( xCompass<(xMagnet+Magnetsizex/2) && xCompass>(xMagnet-(Magnetsizex/2) && yCompass<(yMagnet+Magnetsizey/2) && yCompass>(yMagnet-Magnetsizey/2))
{
test = true; // way to tell it is doing this
b[0] = 225;
b[1] = 225;
}


but when the rectangle area is rotatable by angle cta, i seems to be stuck trying to make the code detect the inside of the area rectangle.

i tried it & probably it has something to do with transformation of the axes,
but it feels rather long in the code


is there a way to do it elegantly? hmmmmmm
 


* areadetectionwithrotation.PNG (17.42 KB, 863x532 - viewed 245 times.)

*** There are 1 more attached files. You need to login to acces it!
« Last Edit: April 22, 2010, 04:47:27 pm by lookang » Logged
Fu-Kwun Hwang
Administrator
Hero Member
*****
Offline Offline

Posts: 3080



WWW
«
Embed this message
Reply #1 on: April 22, 2010, 05:23:47 pm » posted from:Taipei,T'ai-pei,Taiwan

There are at least two ways to do it.
1. Rotate the coordinate system so (x,y) become (x',y'), so it become zero degree again.
And check it by the same method.

2. if the coordinates for those four points are (x1,y1), (x2,y2), (x3,y3) and (x4,y4).
Assume a line L1: y=m_1 x+b_1 pass (x1,y1) and (x2,y2). Then y>m_1a+b_1 is at the right side of the L1, y<m_1 x+b_1 is at left side of L1
Another line L2: y=m_2 x+b_2 pass (x3,y3) and (x4,y4).

If the compass is inside, it must be between L1 and L2.
So you can find out condition (1) : (y-m_1 x-b_1)(y-m_2 x-b_2)<0

There are another two lines
L3 :pass (x1,y1) , (x4,y4)
L4: pass (x2,y2) , (x3,y3)
So you can find out another condition (2): (y-m_3 x-b_3)(y-m_4 x-b_4)<0

The compass is inside if the above two conditions are satisfied at the same time (use and operator ).
Logged
lookang
Hero Member
*****
Offline Offline

Posts: 1784


http://weelookang.blogspot.com


WWW
«
Embed this message
Reply #2 on: April 22, 2010, 10:25:02 pm » posted from:Singapore,,Singapore

u r a genius!
thanks!
i used method one
Code:
xMagnettransform = xMagnet*cs+yMagnet*sc;
yMagnettransform = -xMagnet*sc+yMagnet*cs;
xCompasstransform = xCompass*cs+yCompass*sc;
yCompasstransform = -xCompass*sc+yCompass*cs;



if ( magnetNS==false&&xCompasstransform<(xMagnettransform+Magnetsizex/2) && xCompasstransform>(xMagnettransform-(Magnetsizex/2)) && yCompasstransform<(yMagnettransform+Magnetsizey/2) && yCompasstransform>(yMagnettransform-Magnetsizey/2))
{
test = true;
b[0] = (225*cs)*vectorfieldmaxopposite/100;
b[1] = (225*sc)*vectorfieldmaxopposite/100;
}
it works so beautifully now. Grin alright man super!!

crap, introduce some other bugs, gotta look at it closer again haiz
« Last Edit: April 22, 2010, 10:32:02 pm by lookang » Logged
Pages: [1]   Go Up
  Print  
Never underestimate others. Never overestimate oneself. ...Wisdom
 
Jump to:  


Related Topics
Subject Started by Replies Views Last post
Keep the center gravity inside the surface area of the object on the ground!
Dynamics
Fu-Kwun Hwang 6 21082 Last post March 31, 2017, 01:32:33 am
by karmakshetra
Experiencing molecular motion from inside a gas
Molecular Workbench
concord 0 8441 Last post May 31, 2007, 02:34:13 am
by concord
how to make the logic to detect 12 or 12.00 when the answer is 12.0?
Questions related to EJS
lookang 6 8432 Last post November 18, 2009, 07:40:31 pm
by lookang
Keep the center gravity inside the surface area of the object on the ground!
dynamics
ahmedelshfie 0 2941 Last post June 08, 2010, 06:27:53 pm
by ahmedelshfie
How to detect that the objects are just touching each other, and set the dv/dt=0
Questions related to EJS
lookang 2 3773 Last post June 29, 2010, 02:44:28 pm
by lookang
Powered by MySQL Powered by PHP Powered by SMF 1.1.13 | SMF © 2006-2011, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
Page created in 0.505 seconds with 22 queries.since 2011/06/15