Post Reply 
Programming Challenge: a classic trigonometry problem
03-09-2023, 08:51 PM (This post was last modified: 03-15-2023 11:38 PM by Albert Chan.)
Post: #32
RE: Programming Challenge: a classic trigonometry problem
(03-09-2023 04:57 PM)Gil Wrote:  But I get two real values (solutions ?): 15.98 and 28.3565769436.

The bigger width corresponds to ratio p = v/u < 0
The ladders don't actually cross, but its line extensions does.

(03-08-2023 04:09 PM)Albert Chan Wrote:  (1) and (2): (1+1/p)² * (1-p²) = (a²-b²)/c² = k      .... (3)

We can estimate location of negative p

(1/(-p) - 1)² * (1-p²) = k
(1/(-p) - 1) ≥ √k

(-p) ≤ 1/(√k + 1)

lua> a, b, c = 40, 30, 15
lua> k = (a*a-b*b)/(c*c)
lua> P = fn'p: (1+1/p)^2*(1-p*p) - k'
lua> hi = -1/(sqrt(k)+1) -- guess for p (with negative sign)
lua> S = require'solver'
lua> S.secant(P, 0.9*hi, hi, 1e-9, true)
-0.3618162034940813        -0.34877707736298674
-0.34877707736298674      -0.34699739631288035
-0.34699739631288035      -0.3471286984646765
-0.3471286984646765        -0.34712756456695126
-0.34712756456695126      -0.3471275637878545
-0.34712756378785914
lua> p = _
lua> v = c * (1+p)
lua> u = v / p
lua> u, v
-28.21178023525376      9.793086543182113

Note that u < 0, with ladder *below* ground level.



Let xu = width from ladder "u" to where ladders cross
Let xv = width from ladder "v" to where ladders cross

x = xu + xv

From similar triangles, we have:

p = v / u = xv / xu

Above example, width numbers:

lua> x = sqrt((a+u)*(a-u)) * (u<0 and -1 or 1)
lua> xu = x / (1+p)
lua> xv = p * xu
lua> x, xu, xv
-28.356576943590095     -43.43356430868842      15.07698736509832

Extended lines cross 15 length units from ladder "v", in the opposite direction.

Update:

For extended-line crossed solution, I updated sign of x matching sign of u.
It is more apparent now that ladders never crossed.
It is also more symmetric, with sign of xu also matching sign of u.

Angles between ladders formula is simpler, without needing abs()
Let γ = angles between ladders, or its line extensions.

Area of quadrilateral = ½ a b sin(γ) = ½ (u+v) x = ½ (u v / c) x

sin(γ) = (u v x) / (a b c)

lua> (u*v*x) / (a*b*c) -- sin(γ)
0.43524258739970595
lua> deg(asin(_)) -- γ, in degrees
25.80073109384667
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: Programming Challenge: a classic trigonometry problem - Albert Chan - 03-09-2023 08:51 PM



User(s) browsing this thread: 2 Guest(s)