🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: rec.games.programmer
4 messages
4 total messages Started by Michael Duffy Sat, 01 Aug 1992 17:11
3d geometry... help please.
#379
Author: Michael Duffy
Date: Sat, 01 Aug 1992 17:11
9 lines
931 bytes
Ok, boys and girls, children of all ages... here's something for you to ponder.

I'm trying to figure out the FASTEST way to figure out the angle between two
rays in space, given any three points (say (a,b,c), (d,e,f), and (g,h,i) with 
(d,e,f) as the point where both rays originate).  It has been two many years
since I took Trig or Geometry or whichever math would help me out here.  
Pseudo code, equations, C, Pascal, or Assembly is appreciated.  T
Thanks in advance for any information,
Mike Duffy (mduffy@aludra.usc.edu)
Re: 3d geometry... help please.
#408
Author: Matthew Smith
Date: Tue, 04 Aug 1992 15:28
23 lines
1573 bytes
In article <l7lhdbINNkcc@aludra.usc.edu> mduffy@aludra.usc.edu (Michael Duffy) writes:
>Ok, boys and girls, children of all ages... here's something for you to ponder.
>
>I'm trying to figure out the FASTEST way to figure out the angle between two
>rays in space, given any three points (say (a,b,c), (d,e,f), and (g,h,i) with 
>(d,e,f) as the point where both rays originate).  It has been two many years
>since I took Trig or Geometry or whichever math would help me out here.  
>Pseudo code, equations, C, Pascal, or Assembly is appreciated.  T
>Thanks in advance for any information,
>Mike Duffy (mduffy@aludra.usc.edu)

The thing you need to figure out is which PLANE you want to take the angle in.
An angle of 90 degress in one plane, when looked at from the side, is an angle
of 0 degrees.  Then you just translate the common point to the origin, rotate
one of the vectors to an axes, then use standard geometry.

The 3-d translation/rotation matrices can be found in any book that talks about
3d-geometry.  I don't know them right off of the top of my head.


Matt Smith
msmith@peruvian.utah.edu
Student - University of Utah Department of Computer Science
Re: 3d geometry... help please.
#410
Author: Ian Bell
Date: Tue, 04 Aug 1992 21:26
50 lines
2532 bytes
In article <l7lhdbINNkcc@aludra.usc.edu> mduffy@aludra.usc.edu (Michael Duffy) writes:
>Ok, boys and girls, children of all ages... here's something for you to ponder.
>
>I'm trying to figure out the FASTEST way to figure out the angle between two
>rays in space, given any three points (say (a,b,c), (d,e,f), and (g,h,i) with 
>(d,e,f) as the point where both rays originate).  It has been too many years
>since I took Trig or Geometry or whichever math would help me out here.  
>Pseudo code, equations, C, Pascal, or Assembly is appreciated.  T
>Thanks in advance for any information,
>Mike Duffy (mduffy@aludra.usc.edu)

The easy quantity to calculate here is the cosine of the angle:

   If the vector

      u := (a,b,c) - (d,e,f) = (a-d,b-e,c-f)

   and vector

      v := (g,h,i) - (d,e,f) = (g-d,h-e,i-f)

   then
		      u . v
      cos(angle) =    ------
		      |u||v|

               (a-d)*(g-d) + (b-e)*(h-e) + (c-f)*(i-f)
  = ----------------------------------------------------------------
    sqrt(((a-d)^2 + (b-e)^2 + (c-f)^2)*((g-d)^2 + (h-e)^2 + (i-f)^2))


If you *really* want the angle, this is the accurate way to find it.
Evaluate this expression, and take the arccos of the result.

If subsequently you are going to take more trig functions (like sine
or tangent) of the angle, you can eliminate the need for trig function
evaluation, since there are nice formulas for sin(a) if cos(a)=x/y,
and so on (recall that sin(a)^2 + cos(a)^2 = 1).

You will probably be concerned with the expense of the sqrt and arccos
functions.  The sqrt function is hard to avoid here, but one common
method for dealing with approximations of a trig function, call it
f(x), is to build a table of exact values for f at many x values, 
use a searching technique or direct indexing to find f(x1) and f(x2),
where the desired argument x is between x1 and x2, and use linear 
interpolation between the two f values for your result.
-- 
 					Ian Bell
					(iebell@watcgl.waterloo.edu)
					(iebell@watcgl.uwaterloo.ca)
Re: 3d geometry... help please.
#430
Author: GMM
Date: Wed, 05 Aug 1992 20:07
11 lines
952 bytes
In article <l7lhdbINNkcc@aludra.usc.edu> mduffy@aludra.usc.edu (Michael Duffy) writes:
>I'm trying to figure out the FASTEST way to figure out the angle between two
>rays in space, given any three points (say (a,b,c), (d,e,f), and (g,h,i) with 
>(d,e,f) as the point where both rays originate).

Could you give more information on the accuracy needed?  Depending on the
situation, there are a few different short cuts that you can use since you
are going for the fastest way.  Send more information and be glad to help
if I can.

Gary
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads