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

Username:   Password: 
 RegisterRegister   
 Quit #100
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Insectoid




PostPosted: Tue Dec 02, 2008 12:22 pm   Post subject: Quit #100

So, I've been working on a triangular collision detection program. I wrote a line of code to return the number of degrees in an angle, but it quits the program on that line with an error 'Quit #100'. There are no exit, quit, etc. statements in the entire program. Anyone know what this is?

code:

%length variables created with Math.Distance

%cosine law to get angle
angleC := arccosd ((lengthA **2)+(lengthB**2) - (2*lengthB*lengthC)*(lengthC**2))


Remember, I need help with the error, not the actual triangular collision
Sponsor
Sponsor
Sponsor
sponsor
The_Bean




PostPosted: Tue Dec 02, 2008 1:49 pm   Post subject: Re: Quit #100

The reason for the problem is because arccosd(num:real) where -1<num<1 because cosine is adjacent/hypotenuse and since adjacent is always smaller than the hypotenuse num will have to be between -1 and 1.
I'm guessing your looking for arctand.
Insectoid




PostPosted: Tue Dec 02, 2008 4:17 pm   Post subject: RE:Quit #100

That could be it...

Funny, the equation given to me by my math teacher uses cos...(cosine law).

EDIT: Yeah, I do know trig. Just forgot that equation (I asked specifically for the one that returns angles given only side lengths). Just thought I mentioned that in case people were wondering why I'm asking my math teacher for trig equations...
The_Bean




PostPosted: Tue Dec 02, 2008 10:31 pm   Post subject: Re: Quit #100

Your teacher was right with using the cosine law, but you messed up the formula.
code:

a ** 2 = b ** 2 + c ** 2 - 2 * b * c * cosd (A)
2 * b * c * cosd (A) = b ** 2 + c ** 2 - a ** 2
cosd (A) = (b ** 2 + c ** 2 - a ** 2) / (2 * b * c)
A = arccosd ((b ** 2 + c ** 2 - a ** 2) / (2 * b * c))

So replace it with
Turing:

angleC := arccosd ((lengthA ** 2 + lengthB ** 2 - lengthC ** 2) / (2 * lengthA * lengthB))
Insectoid




PostPosted: Mon Dec 08, 2008 4:28 pm   Post subject: RE:Quit #100

Ah! Thank you! (this was really rushed).

I had put this away for a bit to work on Perl, but I've decided to use it as my FP for CS. After I get it working in Turing, I'll change it to Java (because I want to concentrate on getting it to work without worrying about the complexities of that hideous language).

So, I need to make at least a simple triangular collision detection program, and then perhaps expand it to provide irregular collision detection based on combinations of triangles and rectangles, and then maybe do Asteroids.
Insectoid




PostPosted: Mon Dec 08, 2008 6:10 pm   Post subject: RE:Quit #100

Okay...more issues.

Quit #100 again, on this line:
code:

dotAngleA := arccosd (((dotLengthB **2)+(dotLengthC**2)-(lengthA **2))/(2*dotLengthB*dotLengthC))


This calculates the angle between 2 lines connecting the point to angles b and c. I'll try to supply a diagram to fully explain, as soon I figure out how to add text to an image in Pixen.

My way of doing this is, if any 1 of angles dotAngleA, B, or C are bigger than 180, the dot is not inside the triangle.



Triangle Diagram.jpg
 Description:
Diagram of what the variables actually are
 Filesize:  34.81 KB
 Viewed:  63 Time(s)

Triangle Diagram.jpg


The_Bean




PostPosted: Mon Dec 08, 2008 7:25 pm   Post subject: Re: Quit #100

All i can come up with for you still getting an error is when:
code:

b**2+c**2-2*b*c>a**2

because your numerator would become greater than your denominator making a value greater than 1 or less than -1

EDIT

Now that I see the triangle (you managed edit before i put my post up), I don't think arccosd with produce a value greater than 180.
Insectoid




PostPosted: Mon Dec 08, 2008 7:34 pm   Post subject: RE:Quit #100

hmm...in theory that shouldn't happen...I know it's becoming greater than 1 or less than negative 1. I don't know why though.
Sponsor
Sponsor
Sponsor
sponsor
The_Bean




PostPosted: Mon Dec 08, 2008 7:36 pm   Post subject: Re: Quit #100

Just tested it.
Turing:

for i : -10 .. 10
    put arccosd (i / 10)
end for

arccosd only produces between 0 and 180 because a triangle cannot have an interior angle greater than 180.
Insectoid




PostPosted: Mon Dec 08, 2008 7:38 pm   Post subject: RE:Quit #100

ah! thank you! Now how can I make it calculate over 180? is there a definite number range that will always produce over 180?

EDIT: lol, my 'hmm, that shouldn't happen' was before you edited your post. Razz

EDIT 2: Wait, cos values follow a wave, so there isn't a definite set, is there?

EDIT 3: I'm on the IRC right now, wanna go on there? (if you have time to help me off-board)
The_Bean




PostPosted: Mon Dec 08, 2008 7:43 pm   Post subject: Re: Quit #100

Well since it cannot calculate over 180 were going to have to use something else. So...
You can use my idea from before.
Turing:

if b**2+c**2-2*b*c>a**2 then
   %numerator is greater than denominator and
   %angle will be greater than 180
end if
Insectoid




PostPosted: Mon Dec 08, 2008 7:44 pm   Post subject: RE:Quit #100

Here's my diagram of my other concept: (making this way more complicated than it needs to be)


triangle2.png
 Description:
Triangle/point collision concept 2
 Filesize:  20.9 KB
 Viewed:  67 Time(s)

triangle2.png


The_Bean




PostPosted: Tue Dec 09, 2008 1:28 pm   Post subject: Re: Quit #100

Last night after getting a working concept myself I realized another problem with both of ares, you can have 2 triangles overlapping, but without any of their vertices inside the other. Although depending on the speed and size at wich you have them moving this probably wouldn't happen.


triangle_problem.JPG
 Description:
 Filesize:  4.89 KB
 Viewed:  2299 Time(s)

triangle_problem.JPG


Insectoid




PostPosted: Tue Dec 09, 2008 4:07 pm   Post subject: RE:Quit #100

Oh, crap...Didn't even think of that. Hmm...This is going to be fun! We could try to modify the 'perfect' oval collision into triangles, and thus check previous frames to see if a collision occurred mid-frame.
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  [ 14 Posts ]
Jump to:   


Style:  
Search: