Solve Acute Angle Problem in 2D Sim/Game

  • Thread starter sciwizeh
  • Start date
  • Tags
    Turning
In summary, the conversation discusses the challenges faced while developing a 2D simulation/game where circles navigate a city with various barriers and obstacles. The issue of acute angles causing problems in the movement of the circles is mentioned, and the current method of using a stepping function to adjust the velocity is described. Suggestions are made to improve the method, such as using A* pathfinding instead of just wall avoidance. The code provided is in Java but can be understood by those familiar with other languages.
  • #1
sciwizeh
25
0
So, I'm working on a 2D sim/game in which "people" aka circles travel around a "city" aka plane with boxes and line barriers. In the person step I'm passing a list of line segments, consisting of walls boundaries etc. and I'm having a bit of trouble when two lines meet at an acute angle. When the person heads toward the intersection point, it's velocity bisects the angle and goes directly through. I'm at a loss to how I should make the person turn around. My current stepping function follows, I'm probably not going about this in the most optimal way, but with the exception of the problem mentioned it works well.

the code is in Java, however it should not be difficult to interpret by people familiar with other languages.
Code:
public void step(double dt, ArrayList<Line> lines){
	for(Line l : lines){
		double dist = l.distance(loc);//gets distance from the point to the segment
		if(dist<(rad*LINE_DIST)) {//consider the segment only if we are close
			double dot = l.getVec().dot(vel);//segmentVector*velocity
			double sig = (dot<0) ? -1 : 1;//sign of the dot product
			Vector des =  l.getVec().mul(sig);//velocity that would be parallel 
			Vector steer = des.diff(vel);//vector to transform velocity to dest
			steer.normalize();//just the direction of steer kept
			vel.add(steer.mul(LINE_ADVERSION));//transform velocity to dest frame by frame
			Vector toP1 = loc.diff(l.p1);//vector from the first point of the segment to the location
			sig = (l.getNormal().dot(toP1)<0) ? -1 : 1;//side of the segment point is on
			vel.add(l.getNormal().mul(sig));//adjustment of velocity keeps right angles from causing current acute angle problem
		}
	}
//	vel.noise();//this was the original fix for right angle
	vel.limit(50);//speed limit
	loc.add(vel.mul(dt));//location update
		
}

any help would be appreciated. as I said, I know my method is sloppy at best, but I'm really at a loss.

EDIT: after more testing and commenting out the line vel.add(steer.mul(LINE_ADVERSION)); the acute problem is solved, and it does avoid the lines, but the motion is much too bouncy, like a spring, and it doesn't follow the line at all, which I do like. so i could still use some information if possible
 
Last edited:
Physics news on Phys.org
  • #2
Well, as I can't edit anymore, I'm double posting and bumping because I've decided to automatically generate a graph and go just use A* to find paths. Looking at my intended end result, I really do need path finding that will go around things, so this is likely the best way for my project.
I'm still curious how I might do this with just wall avoidance, so any advice would still be appreciated.
 

1. What is an acute angle problem in a 2D simulation or game?

An acute angle problem in a 2D simulation or game refers to a situation where there is a need to find the solution to an angle that is less than 90 degrees. This can arise in various scenarios such as determining the trajectory of a projectile or navigating a character through obstacles.

2. How do you solve an acute angle problem in a 2D simulation or game?

To solve an acute angle problem in a 2D simulation or game, you can use trigonometric functions such as sine, cosine, and tangent. These functions can be used to calculate the length of sides or angles of a triangle, which is a common shape in 2D simulations and games.

3. What are some common techniques for solving acute angle problems in 2D simulations and games?

Some common techniques for solving acute angle problems in 2D simulations and games include using the Pythagorean theorem, trigonometric functions, and vector mathematics. It is also helpful to break down the problem into smaller components and use basic geometry concepts to find the solution.

4. Are there any tools or resources available for solving acute angle problems in 2D simulations and games?

Yes, there are many online calculators and software programs that can help solve acute angle problems in 2D simulations and games. These tools use complex algorithms and mathematical formulas to accurately calculate angles and distances in a 2D space.

5. How important is it to solve acute angle problems in 2D simulations and games?

Solving acute angle problems is crucial in 2D simulations and games as it allows for accurate and realistic gameplay. These problems are often encountered in physics-based games or simulations and can greatly affect the outcome of the game or simulation. An incorrect angle calculation can lead to unexpected results and decrease the overall quality of the simulation or game.

Similar threads

  • Special and General Relativity
Replies
6
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
2
Views
2K
  • Introductory Physics Homework Help
Replies
4
Views
786
  • Engineering and Comp Sci Homework Help
Replies
1
Views
3K
Replies
3
Views
2K
  • Programming and Computer Science
Replies
1
Views
1K
Replies
3
Views
847
  • Introductory Physics Homework Help
Replies
19
Views
4K
  • General Math
Replies
5
Views
11K
  • Special and General Relativity
2
Replies
42
Views
4K
Back
Top