• Print

Author Topic: please help  (Read 129 times)

23452

  • Jr. Member
  • **
  • Posts: 72
    • Email
please help
« on: December 21, 2012, 06:07:55 PM »
Can someone help with this code. It checks if an object is in-front of another by only using slops. There are some glitches with the logic(namely using exactly .5pi and 1.5pi), but the idea works on paper.

Code: [Select]
DIM ac AS SINGLE
DIM ao AS SINGLE
DIM a AS SINGLE
DIM w AS SINGLE

check = 0
INPUT "a ", a
INPUT "w ", w
INPUT "y ", y
INPUT "x ", x
ex = 0
ey = 0
cy = 1
cx = 1


'get slopes
ao = (y - ey) / (x - ex)
ac = (y - cy) / (x - cx)



'cheack code for object
IF ao < TAN(a) THEN
    check1 = 1
ELSE check1 = 0
END IF

IF ao > TAN(a + w) THEN
    check2 = 1
ELSE check2 = 0
END IF

'cheack code for cheack
IF ac < TAN(a) THEN
    check3 = 1
ELSE check3 = 0
END IF

IF ac > TAN(a + w) THEN
    check4 = 1
ELSE check4 = 0
END IF



'cheack if codes are the same
IF check1 = check3 THEN
    IF check2 = check4 THEN
        check = 1
    END IF
END IF

PRINT check, check1, check2, check3, check4

 

Gorlock

  • Sr. Member
  • ****
  • Posts: 337
    • Email
Re: please help
« Reply #1 on: December 22, 2012, 11:26:03 AM »
Could you give a little more information. I'm not sure what the variables stand for. I am not sure where you are using pi/2 or 3pi/2 but pi is 4*ATN(1) so you can use 2*ATN(1) for pi/2 and 6*ATN(1) for 3pi/2. When you add more information I can probably help you more.

23452

  • Jr. Member
  • **
  • Posts: 72
    • Email
Re: please help
« Reply #2 on: December 22, 2012, 03:18:32 PM »
x and y are the object; ex and ey are the eye; cx and cy are a point that is always in front of the eye.

a is the angle rotated; and w is the window(how wide the vision is)

It checks the slope between the eye and the object(ao I use a for slope because the whole program uses angles), and the slope between the the check point(cx and cy) and the eye(this slope is ac).

They are then compared to slopes of the boundary lines( tan turns angles into slopes) using < and >( it does not matter which one has < and > as long as it is the same on both). There are 4 possible codes. 1,1;1,0;01;0,0.    The code from the object is saved in check 1 and 2. The code for the check point is saved in check 3 and 4. If they have the same code then check = 1, or that is how it is suppose to work.


P.S. the idea is to never use pi, a line ever lands on the y axis

  • Print