Finding diagonal length of quadrilateral using ( for each number block )

I am trying to find solutions to find the unknown diagonal of an irregular quadrilateral, given its area and the lengths of its four sides.

TOTAL AREA = △1 AREA + △2 AREA
Using Heron's Formula
herons-formula

All values ​​are known in the equation except the length of the diagonal X

I used the ( for each number from to ) block to test the numbers that give the same area result, but unfortunately it doesn't work. I don't know what the problem is !! aia file attached

blocks(124)
blocks(125)
blocks(123)

find_diagonal_of_a_quadrilateral(1).aia (93.1 KB)

example results


The long running for loop is blocking the UI,, which results in that error after a while

Use a fast running clock component instead

Taifun

1 Like

There are some mathematical issues regarding your approach.

  • Not all areas can be fitted into a particular set of side lengths. Some may be too large or too small. You don't check for that before sending your app on an impossible task.

  • You check for an exact match, assuming the diagonal to be a rational number that can be enumerated, and assuming that the floating point calculation results will match exactly.

A more appropriate approach would be to use Newton's Method in a Clock Timer to run its steps until you get within some small distance of a solution.

1 Like

Additional thoughts:

  • Your diagonal length iteration range can be made shorter, starting at max(abs(A-B),abs(C-D)) and ending at min(A+B,C+D)

  • You can use a courser iteration step for a first approximation, like min(A,B,C,D)/10 and then use that to home in on a shorter range once you know which sub-range is closest to the solution

If you calculate the difference between target area and calculated area, you would be searching for zero crossings, a known mathematical technique.

P.S. AI2 has easy graph components that could be used to graph the area difference across the domain of diagonal lengths. That could be used to show the iterative nature of the calculations as you home in on the smaller diagonal domains.

This is just to add a bit of showmanship to the app, and to help the viewer see how the process works.

I did not address the nature of the assignment.

Is this a test of coding ability, or a test of knowledge of the trigonometric functions and construction techniques that would result in the creation of a trigonometric formula that should be solved symbolically?

What method did you use to calculate the area of the polygon in the first place ?

The area formula you gave us (Heron) can be expanded into a fourth degree polynomial in x.

The big fat ugly general solution to those is at

https://www.researchgate.net/figure/Roots-of-fourth-order-polynomial-equation_fig13_47715135

I tried to solve it mathematically and derived the fourth degree equation and tried to find the solutions but the results are wrong


The results are imaginary numbers. i

SCREEN2 AIA
find_diagonal_of_a_quadrilateral(2).aia (126.8 KB)

It's virtuous to think mathematically before trying to code a brute force solution.

At first glance, there are two possibilities

  • Fourth degree polynomials can have up to four zero points, just like easy quadratics can have two. Those square roots can be fed negative numbers, resulting in imaginary numbers, which AI2 can handle. You can filter out the imaginary zero point solutions and hope you have left a purely real solution.

  • The problem statement used letters a,b,c,d for triangle side lengths. The polynomial math uses the same letters as coefficients. Confusing them makes for better situation comedy than mathematical rigor.

P.S. My grad school computer science courses were under the wing of the Math department, in a building that looked like the black monolith from the movie 2001.

You could almost hear the movie theme Thus Spake Tharathustra as you approached the building.

:grinning: :grinning: This is just a screenshot of the site you sent me to solve quartic equations.

Finally

Finally, I have reached the correct mathematical solution.

And I assumed that y=x^2 and I solved it as a quadratic equation of the second degree to get y then x
find_diagonal_of_a_quadrilateral_copy.aia (99.9 KB)

There will be only two values ​​for the unknown diagonal .

thanks

image
find_diagonal_of_a_quadrilateral_copy (1).aia (100.2 KB)

For readability, I added Labels to the Textboxes so they can be matched against your diagram.

I tried two variations on the Pythagorean Triangle (3,4,5) so I could easily check the results.
Two of those triangles lined up on the 5 diagonal would have a total area of 12. However, I tried lining them up as a rectangle versus a diamond but always got both diagonals = 5 (see display.)

If you are going to show two results, I assume they are supposed to be the two diagonals?

1 Like

For any irregular quadrilateral, there are two values ​​of the same diagonal in the direction shown in the drawing, and both achieve the same area. However, if the shape is a rectangle, the two diagonals are equal.

image

So, for this kite, must the red line have a length of 5?

It doesn't look like that to me.

If Area = 11.952

Diagonal will be 5 or 4.588

If you're looking for fun math problems, this is my chance to post something some one sent me as a joke:

image

This is a shape with four sides of equal length, with four right angles.
Is it technically a square?

The problem is to draw it on a Canvas.

I unfortunately have other responsibilities (debugging the next AI2 version), so I won't be tackling it.

1 Like

Got it

image

The angle is fixed at 48.25 degrees and the magic number is the relationship between the inner and outer circles' radius, with r being the smaller circle's radius. To be honest this is a close enough is good enough solution, calculation of pi and some roundings, etc.

There are probably other angles that could be used, and the inner circle could be moved away from centre whilst retaining the right angles?

notASquare.aia (5.4 KB)

2 Likes