Math Is Fun Forum
  Discussion about math, puzzles, games and fun.   Useful symbols: √ ∞ ≠ ≤ ≥ ≈ ⇒ ∈ Δ θ ∴ ∑ ∫ π -




Not registered yet?

Post a reply

Go back

Write your message and submit
:) :| :( :D :o ;) :/ :P :lol: :mad: :rolleyes: :cool: | :dizzy :eek :kiss :roflol :rolleyes :shame :down :up :touched :sleep :wave :swear :tongue :what :faint :dunno

Go back

Topic review (newest first)

2012-12-08 04:42:15

John E. Franklin wrote:


Yes, I am allowed to use min() and max() functions, and right now  I actually have an equation similar to the one you showed here. It works perfectly but I still believe there is a way to avoid individual calculations of these distances.
I think, the ray tracing algorithms are dealing with the similar problem. Do we have any experts in 2.5D graphics here? I remember reading some articles on that subject, but it was too many years ago.

John E. Franklin
2012-12-07 18:11:58

Here's an awkward way to avoid absolute value signs:

Abs(X) = (x**2)**(1/2) = (x^2)^(1/2)

Basically square root the square of the interested value.

John E. Franklin
2012-12-07 17:29:47

max value of a and b = (a + b + |a - b|) / 2

minValue(C,D)= (C + D - |C - D|) / 2

Put it all together in one large equation and get...


Now just expand this with you trigonometric equations you have
mentioned in your original post and I believe it is possible.

I hope you are allowed to use the absolute value operator though!!!!

Have a super week...

John E. Franklin
2012-12-07 17:23:53

Hi my friend.  If you are allowed to use the absolute value operator, I do believe an elegant solution will arrive.  For starters, let's couple together the dbottom with the dtop in an expression to find the one that is positive.  And also let's couple together the dleft with the dright in an expression to find the one that is positive meaning non-negative.  In these two cases, we simply need a "maximum finder" equation that uses the absolute value signs.  After these two terms are resolved, they can be embedded in the larger single equation in which the "minimum of two values" is found, and that is the answer.  Now let me give you an idea as to how one would find the max value of two numbers with the absolute value sign.  See next post for more details...

2012-12-07 07:53:53

The problem:
We have a squared box of size w*w.
Inside the box, we have a point at (x,y).
From the point we draw a line at some angle d.
If x, y, d, and w are known, find the distance to the closest wall of the box.

x and y are always positive and less then w (point is always inside the box). The d can be anything.
On the attached image I put two points. I need to know the length of green lines.

From a simple definitions of sin and cos, I have four distances to the four walls of the box
dl = (0 - x) / cos d
db = (0 - y) / sin d
dr = (w - x) / cos d
dt = (w - y) / sin d
From the set {dl, db, dr, dt} remove negative values (those are distances along the same line but in opposite directions).
And the final answer is the minimal from two remaining values.

Looks like the final answer is correct, but solutiona is fairly complicated. Maybe I am not seeing the obvious, but is it possible to reduce this algorithm to a one formula?

Board footer

Powered by FluxBB