Undergrad Area divided by linear function

Click For Summary
SUMMARY

The discussion centers on solving the problem of dividing a convex polygon into two equal-area parts using a linear function of the form y = ax. The original approach involved testing every possible value of 'a' from the y-axis to the x-axis, which proved inefficient and time-consuming. A more effective method involves calculating the polygon's area using Heron's formula, incrementally adjusting 'a', and utilizing interpolation techniques to narrow down the search for the optimal value of 'a' within a tolerance of 0.02. This iterative approach significantly reduces computation time while ensuring accuracy.

PREREQUISITES
  • Understanding of convex polygons and their properties
  • Familiarity with Heron's formula for area calculation
  • Basic knowledge of linear functions and their graphical representation
  • Experience with numerical methods for optimization and interpolation
NEXT STEPS
  • Research Heron's formula for calculating the area of polygons
  • Learn about numerical optimization techniques for iterative solutions
  • Study interpolation methods to improve search efficiency
  • Explore computational geometry concepts relevant to polygon intersection
USEFUL FOR

Mathematicians, computer scientists, and software developers working on geometric algorithms, particularly those interested in optimization problems and computational geometry.

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?
 
Mathematics 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 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 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 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 13 ·
Replies
13
Views
5K
Replies
15
Views
4K
  • · Replies 17 ·
Replies
17
Views
3K
  • · Replies 17 ·
Replies
17
Views
2K
  • · Replies 5 ·
Replies
5
Views
5K
Replies
2
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 13 ·
Replies
13
Views
3K
  • · Replies 24 ·
Replies
24
Views
7K
  • · Replies 24 ·
Replies
24
Views
6K