Go Back   CodingForums.com > :: Server side development > Java and JSP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 05-29-2012, 04:19 PM   PM User | #1
Sammy12
Registered User

 
Join Date: Jun 2011
Posts: 1,063
Thanks: 12
Thanked 241 Times in 240 Posts
Sammy12 is on a distinguished road
Robocode Difficulty Understanding

Hello cf,
I urgently need to know what these lines of code do?

1.
Code:
gravityX = gravityX * 0.85D - Math.sin(bearing) / enemyDist;
gravityY = gravityY * 0.85D - Math.cos(bearing) / enemyDist;
2.
Code:
setTurnRightRadians(Utils.normalRelativeAngle(Math.atan2(gravity
	+ 1.0D / getX() - 1.0D / (fieldX - getX()), gravityY + 1.0D
	/ getY() - 1.0D / (fieldY - getY()))
	- getHeadingRadians()));
This is a code snippet from the DustBunny nano bot, in which uses anti-gravity. I read through the anti-gravity articles, but this doesn't seem like them. Even picking them slightly apart would help me a lot.

I understand the force acting, but was is D?

- Sammy12

Last edited by Sammy12; 05-29-2012 at 04:24 PM..
Sammy12 is offline   Reply With Quote
Old 05-29-2012, 05:08 PM   PM User | #2
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,662
Thanks: 4
Thanked 2,452 Times in 2,421 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
"D" suffix simply indicates that the number in use is a double, not a float. Although best I know Java goes the other way; fractional numbers are double by default and floats must be affixed with F, unlike whole numbers which are integers unless specified as long (ie: 13L;). You can check this against the Number:
PHP Code:
Number n 0.85;
System.out.println(n.getClass().getSimpleName()); 
Returns Double, while:
PHP Code:
Number n 85;
System.out.println(n.getClass().getSimpleName()); 
Returns Integer.

So in Java, 1.0 = 1.0D.

As for the rest of the equations, there's simply no way to describe them aside from what they do. Its clearly calculating rotation movements, but I can't tell you why or for what.
Fou-Lu is offline   Reply With Quote
Users who have thanked Fou-Lu for this post:
Sammy12 (05-29-2012)
Old 05-29-2012, 07:32 PM   PM User | #3
Sammy12
Registered User

 
Join Date: Jun 2011
Posts: 1,063
Thanks: 12
Thanked 241 Times in 240 Posts
Sammy12 is on a distinguished road
Thanks Fou-Lu,

I think gravityX and gravityY are for the X and Y are the forces at a 90 degree angle when head to head with a bot.

The Math.atan2 is the angle of the quotient of the two coordinates (maybe field - coordinate), so basically the perfect angle between X and Y, which is the best angle for the robot to move in.

Thank you for your incite on the "D" that helps make things a lot easier. Did you not want to tell me what the answer was or was there not enough information provided?
Sammy12 is offline   Reply With Quote
Old 05-29-2012, 07:53 PM   PM User | #4
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,662
Thanks: 4
Thanked 2,452 Times in 2,421 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
Not enough information to use. But on top of that I'd have to dust off the old geotrig books to solve the equations to see what its actually doing :P
Fou-Lu is offline   Reply With Quote
Old 05-30-2012, 04:12 AM   PM User | #5
Sammy12
Registered User

 
Join Date: Jun 2011
Posts: 1,063
Thanks: 12
Thanked 241 Times in 240 Posts
Sammy12 is on a distinguished road
haha thanks for all the help it actually really helped me understand what was going on
Sammy12 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 05:07 AM.


Advertisement
Log in to turn off these ads.