Area divided by linear function

Click For Summary

Discussion Overview

The discussion revolves around a computational geometry problem involving a convex polygon in the first quadrant. Participants explore methods to find a linear function of the form y = ax that divides the polygon into two equal areas. The conversation touches on algorithmic approaches, mathematical insights, and the challenges of computational limits.

Discussion Character

  • Exploratory
  • Technical explanation
  • Debate/contested
  • Mathematical reasoning

Main Points Raised

  • One participant describes the problem and their initial approach using a program that tests various values of "a" but fails to meet time constraints.
  • Another participant suggests that the areas are monotonic with respect to the angle of the line, proposing an iterative approach to find the optimal solution without recomputing areas from scratch.
  • A different participant points out the impracticality of trying every possible value of "a" as it is a real number, but acknowledges the finite nature of floating-point representations in programming.
  • Several participants discuss methods to optimize the search for "a," including using averages and interpolation based on previous area calculations.
  • There is a back-and-forth regarding the efficiency of the proposed step sizes for "a," with some suggesting that larger increments could be sufficient.
  • Participants express uncertainty about the adequacy of their approaches, particularly concerning time limits and computational efficiency.

Areas of Agreement / Disagreement

Participants do not reach a consensus on the best method to solve the problem. There are multiple competing views on the efficiency of different algorithms and the appropriateness of step sizes for "a."

Contextual Notes

Limitations include the dependence on the specific implementation of floating-point arithmetic in programming, the unresolved nature of the optimal algorithm, and the challenge of meeting strict time limits while processing multiple polygons.

YoungPhysicist
Insights Author
Messages
350
Reaction score
203
The original problem for anyone that can read Chinese:
https://zerojudge.tw/ShowProblem?problemid=b221
The problem defines a convex polygon with multiple points located in the first quadrant and the required task is to find a linear function y = ax that can spilt the polygon into two parts each with the same area.(The “a” can be within the accuracy of 0.02 from the actual answer,see why in a second)

Since this is actually a program question (Like the ones on Project Euler or UVa) so I originally wrote a program that basically tries every possible a value from y-axis to x-axis(via survey formula),but my program fail to finish in the time limit,so I think this problem may require some math insight which I don’t have.

Are there any suggestions on how this might have been done?Since it leaves a space for error,does it has something to do with calculus?
 
Physics news on Phys.org
The two areas are monotone with respect to the angle of your straight line: Increase the angle relative to the x-axis and the upper area will never increase while the lower area will never decrease. Instead of trying everything you can find the optimal solution iteratively.

You also don't have to recompute the area each time, extrapolating from the previous value should work reasonably well once you are somewhat close to the solution.
 
  • Like
Likes   Reactions: YoungPhysicist
Young physicist said:
The problem defines a convex polygon with multiple points located in the first quadrant and the required task is to find a linear function y = ax that can spilt the polygon into two parts each with the same area.(The “a” can be within the accuracy of 0.02 from the actual answer,see why in a second)

Young physicist said:
Since this is actually a program question (Like the ones on Project Euler or UVa) so I originally wrote a program that basically tries every possible a value from y-axis to x-axis(via survey formula),but my program fail to finish in the time limit,so I think this problem may require some math insight which I don’t have.
First, it's not possible to try "every possible a value," since a is a real number, and there are uncountably many of them. However, if you're writing a computer program, there are only a finite number of floating point values between any two adjacent integers, due to the limited storage used by floating point numbers. It would be possible to check all of the floating point values for a between, say 0 and 1, but it would take some time to do this.

Second, I don't understand what you are saying here: "a program that basically tries every possible a value from y-axis to x-axis..." The equation of the line is ##y = ax##, so it crosses the x and y axes at the origin and nowhere else. The line y = ax does not cross from the x-axis to the y-axis.

How I would solve the problem:
1. Calculate the area A of the polygon, using Heron's formula (do a web search if you don't know it)
2. Determine the smallest value of a so that the line y = ax intersects the polygon only at a corner point
3. Increment a by some fixed amount
4. Find the two points on the polygon at which the current line y = ax intersects the polgon
5. Find the area of either part of the intersected polygon
6. If the area you found equals A/2 (or is close enough), then stop.
7. Otherwise, go to step 3.
 
  • Like
Likes   Reactions: YoungPhysicist
Faster: Find the smallest and largest value of a for an intersection (let's call them B and C). Take the average (or the average angle - a bit more time-consuming to calculate but gives a better result) D, check which area is larger (if we are not within the tolerance yet), consider (B+D)/2 or (C+D)/2 as next value for a, depending on which side was larger. Repeat, reducing the remaining search space by a factor 2 each time.

Even faster: Do some interpolation instead of simple averages. As an example, if the upper area was 55% of the total area, we are probably quite close to the target value already and should search closer to that number.
 
  • Like
Likes   Reactions: YoungPhysicist
@mfb and@Mark44:
My point is that I make the program to try the a value from 0.02 all th way to 100 with every 0.02 as a step,that is good enough for this case,sorry for the mistake above:-p
 
I thought that was too slow?
Young physicist said:
but my program fail to finish in the time limit

Steps of 0.04 would be sufficient, by the way.
 
mfb said:
I thought that was too slow?
Yeah,that’s why I post the problem on this forum
 
Then why do you say it is good enough in post 5?
 
Cause the time limit for the test point is 2 seconds and each testppint have 40 to 50 polygons to deal with in a row,and my original program takes 1 second per polygon,which clearly won’t make it.
 

Similar threads

  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 13 ·
Replies
13
Views
5K
Replies
15
Views
4K
  • · Replies 17 ·
Replies
17
Views
3K
  • · Replies 24 ·
Replies
24
Views
7K
  • · Replies 7 ·
Replies
7
Views
3K
  • · Replies 17 ·
Replies
17
Views
2K
  • · Replies 5 ·
Replies
5
Views
5K
  • · Replies 3 ·
Replies
3
Views
2K