1. Distance and Angles in Multiple Dimensions

First of all, although this thread started with a question of Patrat, I wont
think he's very interested in 4th and 5th dimensions. So this if for fun,
and not practicle reasons. Nevertheless, why not have a look at Micheal
Sibal's code, since he mentioned it. (thanx)

However, for theory and fun, its nice to speculate on these things.
Hawke, said the theory only works for right triangles, but consider a
one-dimensional surrounding:

It would be length^2 = length^2 + nothing^2
Hmm, it would say both sides are of equal length.. woops.. heh! Thats true!
Pythagoras was way above triangles it seems blink

Plus no angle is undefined. We are comparing two directions, of which one is
blindly chosen. (angle 0)
An angle of 180 degrees. Will have one of the two values as a zero. (since
the horizontal difference is nothing)

I would say, this is the ending function:
Anyone (theoretically) disagrees, since we cant test it in practise ?

function relat (object a, object b)
sequence angles
atom dist

    if atom (a) and atom(b) then
        if a >= b then
            return { a-b, 0}
        else
            return { b-a, 1.5708}
            -- Any1 wants to replace 1.5708 with something more precize ?
        end if
    end if
    a = a - b
    b = a * a
    a = a + (a = 0) * 0.000000000000000001    -- Precize enough ?
    angles = {arctan(a[1]/a[2])}
    dist = b[1]
    for index = 2 to length(a) do
        dist = dist + b[index]
        angles = append(angles, arctan(sqrt(dist), b[index])
    end for
    return prepend(angles, sqrt(dist))
end function

-- We might need to 'round' the result a little.

Ralf

new topic     » topic index » view message » categorize

2. Re: Distance and Angles in Multiple Dimensions

Ralf Nieuwenhuijsen wrote:
>Anyone (theoretically) disagrees,
>since we cant test it in practise ?
ummmm i think i might gotta :)

>-- Any1 wants to replace 1.5708 with something more precize ?
constant PI    =arctan(1)*4
constant HALFPI=PI/2

> function relat (object a, object b)
> sequence angles
> atom dist
>     if atom (a) and atom(b) then
>         if a >= b then return { a-b, 0}
>         else  return { b-a, HALFPI}
--btw, i'm debating if that's actually right...
--after all, when talking radians, it goes from
-- -pi/2 to pi/2, so 0degrees is -pi/2 and 180 is pi/2
--or if you make 0degrees = -pi/2 then 180 is PI and
--90 is pi/2.
--therefore, shouldnt the line read either:
-- 1>   if a>=b then return {a-b,-HALFPI}
--      else return {b-a,HALFPI}
-- OR
-- 2>   if a>=b then return {a-b,0}
--      else return {b-a,PI}
--or am i really thinking screwy here?

>         end if
>     end if
>     a = a - b
--we might want to make this a=b-a... i'm thinking we're
--going to get into having occassional upsidedownness...

>     b = a * a
>     a = a + (a = 0) * 0.000000000000000001    -- Precize enough ?
>     angles = {arctan(a[1]/a[2])}
--first actual oopsie :)
--let's make this angles={arctan(a[2]/a[1])}, shall we? :)

>     dist = b[1]
>     for index = 2 to length(a) do
>         dist = dist + b[index]
>         angles = append(angles, arctan(sqrt(dist), b[index])
--second oopsie :)
--how about:
--instead???
--wouldn't that be right?? :)
>     end for
>     return prepend(angles, sqrt(dist))
--why not simply: return {sqrt(dist),angles} ??
--saves a nonneeded function call, and i think it's
--a little easier to read... :) just my opine, mind you...
> end function

i'm purty sure of the corrections i made, but of course,
i'm not wholeheartedly sure :)

--Hawke'

new topic     » goto parent     » topic index » view message » categorize

3. Re: Distance and Angles in Multiple Dimensions

I stand completely corrected, Hawke.
For me the word speculate is pretty much how I made the function.
And indeed a lot of brainfarts. Oh well, Im not accurate enough for match.
Im used to Euphoria telling me I did something wrong, and what Im doing
wrong. Esspecially during math tests, I need to remember, that my result
isnt a prototype or something, oh well, we figured it out now, havent' we ?
Ive removed the '>' and stuff, so people can easily cut & paste, if they
ever wanne make some science fiction game blink

function relat (object a, object b)
sequence angles
atom dist

    if atom (a) and atom(b) then
        if a>=b then return {a-b,0}   -- angles start at zero, end of
discussion blink
                    else return {b-a,PI}
        end if
    end if
    a = a - b
    -- Not the fastest approuch though:
    a = a * ((a < 0 * -1) + (a > 0))
    b = a * a
    -- Jiri or any other math magician wanne help out here ?
    -- This will work, but if any one has a more idealistic approuch to
handle the
    -- division by zero thingie ?
    -- Or do I need to look this up in some old math book ?
    a = a + (a = 0) * 0.000000000000000001
    angles={arctan(a[2]/a[1])}
    dist = b[1]
    for index = 2 to length(a) do
         dist = dist + b[index]
        angles=append(angles,arctan(a[index],sqrt(dist)))
    end for
    return {sqrt(dist),angles}
end function

new topic     » goto parent     » topic index » view message » categorize

4. Re: Distance and Angles in Multiple Dimensions

Ralf Nieuwenhuijsen wrote:
> function relat (object a, object b)
>     a = a - b
>     -- Not the fastest approuch though:
>     a = a * ((a < 0 * -1) + (a > 0))
ummmm.... i don't really think the line above is quite
the ticket... you're trying to make sure there are no
negative values... but you *want* the signs... arctan()
depends on sign(+-) to determine which of 2 quadrants
your vector is running.  this will return only one
quadrant's worth of vectors...

when I wrote the any angle line drawing routines for
the truecolor.e library, i made sure that startX was
less than endX
  (since we are dealing with CRT coordinates, 0,0=upleft)
and then I *kept* the sign for the Y values.
this will return a line that is properly going up or down...

i've found it simplest to just do a=b-a, and in the arctan
part, make it arctan(opposite/absolute(adjacent))....

>This will work, but if any one has a more idealistic approuch to
>handle the division by zero thingie ?
>     a = a + (a = 0) * 0.000000000000000001
>     angles={arctan(a[2]/a[1])}
how about simply:
   if a[1]=0 then angles={0}
   else angles={arctan(a[2]/abs(a[1])}
   end if
this will keep your precision for *large* universes/coordinate
systems (as when they may be using viewport.e???)

naturally, same as above goes here as well...

justa my thoughts...--Hawke'

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu