Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Improvements...
#31
I spend a lot of time in trains, because of my job (100 000 km per year on an average basis). All the consultants have a laptop, I have to admit I'm always annoyed when I try to use a regular mouse.

Regular mice have a major default: if you leave your mouse lying on the back during lunch time, for example, it dies, because it cannot get back on its feet by itself. And that's a shame :rotfl:
hink Global, Make Symp' All ! ®
[Image: Banner.gif]
Reply
#32
Well, a train is another thing. You said buses, I was trying to imagine you programming in an urban bus...
Antoni
Reply
#33
I think I found where is the problem giving wrong pixels in TCRay. I have tested the Equa3 routine outside the program and it gives huge errors when the equation has a single solution.
Antoni
Reply
#34
I prog both in trains and city buses ! And also during lunch at the restaurant...

That's great news if you can fix that bug in Equa3, because I have some trouble with the cubic shapes also : the result is esthetic, but I know it's wrong...

I was almost sure there was a bug of that kind...
hink Global, Make Symp' All ! ®
[Image: Banner.gif]
Reply
#35
If i can fix it... I was never taught how to solve third and fourth degree equations, so i'm checking all sites I can find about this issue. And all algorithms differ in a place or two...
Antoni
Reply
#36
I FOUND IT!
Just divide by a3# the last term of the formula of the single root..
Code:
x1# = Sqr3#(-q# / 2 + SQR(Delta3#) / 2) + Sqr3#(-q# / 2 - SQR(Delta3#) / 2) - a2# / 3/A3#
Antoni
Reply
#37
I have also found this bug during lunch, thanks to your remark. I first thought it came from a bad cut&paste, but the bug has been here since march when I wrote the routine :lol:

Thanks a lot Antoni, I would never have found it, I was sure the routine was OK until now (remember the Bike Mirrors pic: the bug had no consequence), I thought only about Probe.Cubic

There was something else... Since I had bad results with the cubic shapes because of that bug, I had added a stupid Dist1=ABS(Dist1) in Probe.Cubic

The following shape is:
(x^2+y^2+z^2-r^2)*z=0

That means it's a sphere multiplied by a plan. The result is now correct: an horizontal plan, with a half sphere emerging from that plan.
Here's the picture with the bug in Equa3 and Probe.Cubic:
[Image: TcRay8.jpg]
Here's the picture after correction of Equa3:
[Image: TcRay8d.jpg]
Here's the picture after correction of the two bugs:
[Image: TcRay8e.jpg]

Much less interesting, but exact...
hink Global, Make Symp' All ! ®
[Image: Banner.gif]
Reply
#38
Ther is another weird thing, in the Equa4, but this one will be more dificult to track. Equa4 gives unaccurate results, but the test program for solvers you wrote long ago is ok.
The only difference i can detect is now you divide all coefficients by a4 before starting to solve. It should not be the only reason...
Edit:
The results are not wrong, simply substituting the roots in the equation it gives a result under 100, when the first version gave 10e-5.
Antoni
Reply
#39
In Tc-Ray v1, the dimensions were in pixels, and that forced the equations solvers to handle both huge and very small numbers.

Tc-Ray handles more classical dimensions (the larger distances are clipped around 30, and a typical object reference size is 1).

So I can try getting rid of the rounding functions on a3# and a4#...
hink Global, Make Symp' All ! ®
[Image: Banner.gif]
Reply
#40
Well, I corrected some lines, but without impact on the final result...

I should calculate a3# / a4# / 4 once at the beginning, for speed...

Now the cubics work fine, I have regenerated the "Bike Mirrors" pic:

[Image: Bike2.jpg]

Code:
SUB Equa4 (a4#, a3#, a2#, a1#, a0#, x1#, x2#, x3#, x4#, Err4%, nSol4%)
' Fourth degree equation resolution - Ferrari method

DIM u#(3)

IF a4# = 0 THEN
Equa3 a3#, a2#, a1#, a0#, x1#, x2#, x3#, Err4%, nSol4%
EXIT SUB
END IF

bdim# = a3# / a4#: cdim# = a2# / a4#: ddim# = a1# / a4#: edim# = a0# / a4#

Fa4# = cdim# - 3 / 8 * bdim# * bdim#
Fa3# = bdim# * bdim# * bdim# / 8 - bdim# * cdim# / 2 + ddim#
Fa2# = bdim# * bdim# * cdim# / 16 - 3 / 256 * bdim# * bdim# * bdim# * bdim# - ddim# * bdim# / 4 + edim#


' BiQuartic case
IF Fa3# = 0 THEN
Equa2 1, Fa4#, Fa2#, x21#, x22#, Err4%, nSol2%

IF Err4% <> 0 THEN
nSol4% = 0
EXIT SUB
END IF

IF nSol2% = 0 THEN
nSol4% = 0
EXIT SUB
END IF

IF x21# < 0 AND x22# < 0 THEN
nSol4% = 0
EXIT SUB
END IF

nSol4% = 4

IF x21# >= 0 THEN
x1# = SQR(x21#) - a3# / a4# / 4
x2# = -SQR(x21#) - a3# / a4# / 4
END IF

IF x22# >= 0 THEN
x3# = SQR(x22#) - a3# / a4# / 4
x4# = -SQR(x22#) - a3# / a4# / 4
END IF

IF x21# < 0 AND x22# >= 0 THEN
nSol4% = 2
x1# = x3#: x2# = x4#
x3# = 0: x4# = 0
END IF

IF x22# < 0 AND x21# >= 0 THEN
nSol4% = 2
x3# = 0: x4# = 0
END IF

END IF

IF Fa3# <> 0 THEN

Equa3 1, -Fa4#, -4 * Fa2#, 4 * Fa4# * Fa2# - Fa3# * Fa3#, u#(1), u#(2), u#(3), Err3%, nSol3%
Choice% = 0

FOR k% = 1 TO nSol3%
IF u#(k%) > Fa4# THEN
SF# = SQR(u#(k%) - Fa4#)
ELSE
GOTO Skip:
END IF

d1# = SF# * SF# - 4 * (u#(k%) / 2 + Fa3# / 2 / SF#)
d2# = SF# * SF# - 4 * (u#(k%) / 2 - Fa3# / 2 / SF#)

IF d1# >= 0 OR d2# >= 0 THEN Choice% = k%: EXIT FOR
Skip:
NEXT k%

IF Choice% = 0 THEN nSol4% = 0: EXIT SUB

U0# = u#(Choice%)
SF# = SQR(U0# - Fa4#)
a1# = SF#
b1# = Fa4# - U0#
C1# = SF# * U0# / 2 + Fa3# / 2
d1# = b1# * b1# - 4 * a1# * C1#
a2# = SF#
b2# = U0# - Fa4#
C2# = SF# * U0# / 2 - Fa3# / 2
d2# = b2# * b2# - 4 * a2# * C2#
Equa2 a1#, b1#, C1#, fx1#, fx2#, Err21%, nSol21%
Equa2 a2#, b2#, C2#, fx3#, fx4#, Err22%, nSol22%
nSol4% = nSol21% + nSol22%
IF nSol21% = 2 AND nSol22% = 0 THEN
x1# = fx1# - a3# / a4# / 4
x2# = fx2# - a3# / a4# / 4
END IF
IF nSol21% = 0 AND nSol22% = 2 THEN
x1# = fx3# - a3# / a4# / 4
x2# = fx4# - a3# / a4# / 4
END IF
IF nSol21% = 2 AND nSol22% = 2 THEN
x1# = fx1# - a3# / a4# / 4
x2# = fx2# - a3# / a4# / 4
x3# = fx3# - a3# / a4# / 4
x4# = fx4# - a3# / a4# / 4
END IF

END IF

END SUB
[/img]
hink Global, Make Symp' All ! ®
[Image: Banner.gif]
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)