Jump to content

Format Neutral Challenge


SEANT

Recommended Posts

Here is a geometry/trigonometry challenged inspired by a question I found on a math forum.

 

The challenge is meant to be language neutral (my solution is via Excel spreadsheet), so viable solutions can be anything from written mathematical expressions to standalone EXEs. The interesting part, I think, is the procedures/algorithms each participants use to derive an answer.

 

The images show the relational constraints, and the challenge is to calculate the area based on a variable radius (0

I’ll post my spreadsheet shortly.

ConstraintDyn.gif

Region.jpg

Link to comment
Share on other sites

  • Replies 30
  • Created
  • Last Reply

Top Posters In This Topic

  • SEANT

    14

  • Lee Mac

    11

  • eldon

    5

  • Organic

    1

Top Posters In This Topic

Posted Images

At first sight of the problem, it strikes me that the radius can only get up to 0.5 if the circle is to stay within the bounding box.

 

And the value of the area is 0 when r=0.5

Link to comment
Share on other sites

At first sight of the problem, it strikes me that the radius can only get up to 0.5 if the circle is to stay within the bounding box.

 

And the value of the area is 0 when r=0.5

Oops. Good catch . . . .that should read (0

Link to comment
Share on other sites

It appears that my little challenge here is not fairing so well against other weekend free time alternatives. Perhaps it will seem more appealing compared to workday drudgery. :)

 

In any event, I’ll post the spreadsheet Tuesday evening (UTC - 5).

Link to comment
Share on other sites

With regards to the line tangential to the 4th quadrant of the circle in the two images above, must it always pass through the top right point of the bounding box?

Link to comment
Share on other sites

With regards to the line tangential to the 4th quadrant of the circle in the two images above, must it always pass through the top right point of the bounding box?

Yes. And the line going from lower right to upper left is always perpendicular to that line.

 

Attached is the AutoCAD 2010 drawing shown in the images.

ConstrCTChall.dwg

Link to comment
Share on other sites

Indeed it is. :)

 

Excellent :)

 

My solution is written in LISP (of course), but more important is the explanation of the method, so I shall put something together to explain my thought process.

Link to comment
Share on other sites

The thought process is the interesting part. I'm hoping that process is available to anyone, programmers or not.

Link to comment
Share on other sites

Ok, first let me apologise for the poor diagrams - its much easier to express maths with a pen and paper than in AutoCAD...

 

I believe the problem can be reduced to finding two lengths (marked yellow and green) by dividing the area (by red line) as follows:

 

Im1.png

 

After these lengths have been determined, the length of the red line in the above diagram may be calculated (using Pythagoras), and I then have all the lengths required to calculate the area of the two right-angled triangles forming the bounded area.

 

First, to calculate the length of the green line:

 

Im2.png

 

Note that the length of the main diagonal is sqrt(2) and the length of the segment from the bottom-left corner to the center of the circle is (sqrt(2)*r) (by Pythagoras on 'r').

 

And so, the main diagonal minus the smaller segment is the hypotenuse of the triangle formed by our green length, and the radius.

 

Now, using Pythagoras, I can solve for the green length.

 

For the yellow length:

 

Im3.png

 

First, I calculate the angle formed by the line from the center of the circle to the top-right corner, and the line from the top-right corner going tangent to the circle using right-angled triangle trig.

 

Using the fact that the angle between the main diagonal and the side of the square is pi/4, and that the two tangent lines are perpendicular, I can deduce the angle marked 'theta' (on the right).

 

Then, using the rules for parallel lines (sides of the square), I know the two angles marked 'theta' are identical.

 

Now, since the triangles subtended from angle theta are isosceles, I can get the yellow length by using right-angled trig on one of the triangles, the radius and the angle theta/2.

 

With both lengths, the area can be solved by calculating the area of both right-angled triangles and adding these areas together.

 

In LISP (I have simplified some of the expressions using a little algebra):

 

(defun AreaCalc ( r / side1 side2 side3 area1 area2 )

 (setq side1 (- (sqrt (+ (- (* r r) (* 4. r)) 2.)) r)
       side2 (+ r (/ r (tan (+ (/ pi 8.) (* 0.5 (asin (/ r (* (sqrt 2.) (- 1. r)))))))))
       side3 (sqrt (1- (+ (* side1 side1) (* side2 side2))))
       area1 (* 0.5 side1 side2)
       area2 (* 0.5 side3)
 )
 (+ area1 area2)
)

(defun tan ( x )
 (if (not (equal 0. (cos x) 1e-) (/ (sin x) (cos x)))
)

(defun asin ( x )
 (if (<= (abs x) 1.)
   (if (equal (abs x) 1. 1e-
     (* x pi 0.5)
     (atan x (sqrt (- 1. (* x x))))
   )
 )
)

Link to comment
Share on other sites

I used a very similar process with my spreadsheet, though I calculated the oversized triangle, the outcropped triangle, and then subtracted.

Region2.jpg

 

 

I think there are some fundamentally different methods out there – so additional participants still have something to offer. As a matter of fact, this relationship with the oversized triangle approach is rather tantalizing.

[ATTACH]28018[/ATTACH]

Relation.jpg

Link to comment
Share on other sites

I am afraid that my trigonometry days are long gone, and that I draw everything now.

 

One interesting feature is that starting with a radius of 0 and the area is 0.5, then the area increases up to a radius of approximately 0.08, and then it decreases to 0 when the radius is 0.5.

 

I am sure that someone will be able to calculate what the maximum area is, and at what radius. :D

Link to comment
Share on other sites

. . . .

 

One interesting feature is that starting with a radius of 0 and the area is 0.5, then the area increases up to a radius of approximately 0.08, and then it decreases to 0 when the radius is 0.5.

 

I am sure that someone will be able to calculate what the maximum area is, and at what radius. :D

 

 

Interesting. That smacks of Calculus. "Extra credit”, if ever I've heard it.:geek:

Link to comment
Share on other sites

Interesting. That smacks of Calculus. "Extra credit”, if ever I've heard it.:geek:

 

Definitely, I suppose you could manipulate the algebra to get Area as a function of Radius, then differentiate to find the maximum, but that is definitely a lot of work since the function is pretty messy.

 

Instead, here is a quick numerical plot of area against radius:

 

AreaPlot.png

 

Increment    Max Area            Radius
----------------------------------------------
0.1          0.526754310161798   0.1
0.01         0.528145452121050   0.08
0.001        0.528152429205519   0.081
0.0001       0.528152940216713   0.0814
0.00001      0.528152947694428   0.08136
0.000001     0.528152947730594   0.081357

Edited by Lee Mac
Link to comment
Share on other sites

Considering the relatively low interest for this thread in the LISP forum, perhaps it might be worth posting a link to it from a different forum board so that those who don't visit the LISP forum regularly are aware of the challenge and can participate?

 

EDIT: I see you already have :(

Link to comment
Share on other sites

Personally speaking, I just click on "What's New", and look at anything that has an intriguing thread title. So it would not matter to me as to which Forum section something was posted.

 

I have not registered with the Swamp (some links need you to be registered) as it seems a bit less inviting than CADTutor and a bit more complicated to get around, so I probably miss a lot. :cry:

Link to comment
Share on other sites

Personally speaking, I just click on "What's New", and look at anything that has an intriguing thread title. So it would not matter to me as to which Forum section something was posted.

 

Oh I see - I tend to go to the LISP forum to see whats new, then look around after that, so I wondered if other members perhaps stuck to their 'favourite' forum boards.

 

I have not registered with the Swamp (some links need you to be registered) as it seems a bit less inviting than CADTutor and a bit more complicated to get around, so I probably miss a lot. :cry:

 

TheSwamp has a different atmosphere to CADTutor, and is far more programming oriented. I prefer it in that I am challenged more by some of the threads there since most of the members are experienced and very clever programmers; whereas the LISP forum here is more of a 'beginners' forum by comparison, for those just starting out with LISP. I'm not saying that there aren't beginners at theSwamp, but more that we don't see the same number of experienced programmers here at CADTutor. Anyway, that's just my thoughts, don't read too much into it - I do like to participate at both forums.

Link to comment
Share on other sites

Wow.

 

I sure do like to complicate things.

 

New method:

 

(defun AreaCalc ( r / x1 x2 )
 (setq x1 (- 1 (* 2 r))
       x2 (sqrt (+ (* (- r 4) r) 2))
 )
 (- x1 (* 0.5 x1 x1 (/ (- x2 r) (+ x2 r))))
)

The method derives from the curious fact that the area of the oversized triangle (derived from the diagonals of the unit square and radius as suggested by Sean above) is equal to 1-2r which just so happens to be the length of a side of the smaller triangle (derived from Pythagoras on the oversized right-angled triangle):

 

Ex1.png

 

This elegance is somewhat spoiled however by the method to calculate the area of the smaller triangle, since the sides of the oversized triangle are used in the calculation, which introduces ugly square roots. I strived for quite a while to find a method which didn't involve trig on the interior angle of the smaller triangle and hence retain the elegance of the solution.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...