POV-Ray : Newsgroups : povray.advanced-users : Math question Server Time
30 Jul 2024 04:14:02 EDT (-0400)
  Math question (Message 1 to 7 of 7)  
From: Pabs
Subject: Math question
Date: 9 May 2000 23:34:51
Message: <3918D8BA.79E41F33@hotmail.com>
Say I have a ray represented by a ray origin & a unit length direction
vector and
a point some-where along the ray - how do I find the distance along the
ray in the direction of the ray's direction vector from the origin  - ie
in the below diagram the distance found would be negative

ray --------------|------------------------------------->
         ^       ray
         |      origin
      point on   dist = 0
        ray
      dist = -1


Post a reply to this message


Attachments:
Download 'us-ascii' (1 KB)

From: Warp
Subject: Re: Math question
Date: 10 May 2000 06:44:41
Message: <39193d98@news.povray.org>
#macro Dist(RayOrigin, Direction, Point)
  ((Point.x-RayOrigin.x)/Direction.x)
#end
// supposing that 'Direction' actually is a unit vector

-- 
main(i,_){for(_?--i,main(i+2,"FhhQHFIJD|FQTITFN]zRFHhhTBFHhhTBFysdB"[i]
):5;i&&_>1;printf("%s",_-70?_&1?"[]":" ":(_=0,"\n")),_/=2);} /*- Warp -*/


Post a reply to this message

From: Chris Huff
Subject: Re: Math question
Date: 10 May 2000 09:02:51
Message: <chrishuff_99-0FD131.08061210052000@news.povray.org>
In article <3918D8BA.79E41F33@hotmail.com>, Pabs <pab### [at] hotmailcom> 
wrote:

> Say I have a ray represented by a ray origin & a unit length direction
> vector and
> a point some-where along the ray - how do I find the distance along the
> ray in the direction of the ray's direction vector from the origin  - ie
> in the below diagram the distance found would be negative

I think you are looking for the distance between two points. In POV 
scenes, just use vlength(PtA-PtB). If in a POV patch, I think there is a 
VDist() macro.
If in something else, it can be implemented like this:

double vdist(double x, double y, double z, double a, double b, double c)
{   return sqrt(sqr(x-a) + sqr(y-b) + sqr(z-c));}

Of course, you should probably use some kind of vector data type to 
simplify things.

This gives you the distance, the direction(+/-) should be pretty easy to 
figure out.

-- 
Christopher James Huff - Personal e-mail: chr### [at] yahoocom
TAG(Technical Assistance Group) e-mail: chr### [at] tagpovrayorg
Personal Web page: http://chrishuff.dhs.org/
TAG Web page: http://tag.povray.org/


Post a reply to this message

From: Peter Popov
Subject: Re: Math question
Date: 10 May 2000 15:45:20
Message: <sqejhso8m5hqbugjhcpgsru1jiipjgf2vv@4ax.com>
On 10 May 2000 06:44:41 -0400, Warp <war### [at] tagpovrayorg> wrote:

> // supposing that 'Direction' actually is a unit vector

Or if it's not:

#macro Dist(RayOrigin, Direction, Point)
  #local Dir=vnormalize(Direction);
  ((Point.x-RayOrigin.x)/Dir.x)
#end


Peter Popov ICQ : 15002700
Personal e-mail : pet### [at] usanet
TAG      e-mail : pet### [at] tagpovrayorg


Post a reply to this message

From: Pabs
Subject: Re: Math question
Date: 10 May 2000 22:01:20
Message: <391A13E8.53BB7F05@hotmail.com>
Peter Popov wrote:

> > // supposing that 'Direction' actually is a unit vector
>
> Or if it's not:
>
> #macro Dist(RayOrigin, Direction, Point)
>   #local Dir=vnormalize(Direction);
>   ((Point.x-RayOrigin.x)/Dir.x)
> #end
>

Will try this - actually this is for part of a patch (ParticlePatch)
Chris Huff wrote:

> I think you are looking for the distance between two points. In POV
> scenes, just use vlength(PtA-PtB). If in a POV patch, I think there is a
> VDist() macro.
> If in something else, it can be implemented like this:
>
> double vdist(double x, double y, double z, double a, double b, double c)
> {   return sqrt(sqr(x-a) + sqr(y-b) + sqr(z-c));}
>
> Of course, you should probably use some kind of vector data type to
> simplify things.
>
> This gives you the distance, the direction(+/-) should be pretty easy to
> figure out.

I tried using VDist & the result is always positive because -ve * -ve = +ve

Thanks all
Pabs


Post a reply to this message

From: Chris Huff
Subject: Re: Math question
Date: 10 May 2000 22:28:19
Message: <chrishuff_99-9914E0.21314010052000@news.povray.org>
In article <391A13E8.53BB7F05@hotmail.com>, Pabs <pab### [at] hotmailcom> 
wrote:

> I tried using VDist & the result is always positive because -ve * -ve = 
> +ve

The point direction should not be difficult to figure out...something 
like this maybe(I am tired and this is untested, so be warned):
O = ray origin(vector)
Pt = point on ray(vector)
Dir = ray direction(normalized vector)
Dist = point distance, calculated with VDist(floating point)

DBL cosA = 0;
VECTOR tmp;
VSub(tmp,Pt,O);
VNormalizeEq(tmp);
VDot(cosA, Dir, tmp);

if(cosA<0)
{   Dist *= -1;}


This basically flips the number(positive to negative) if the point and 
the direction are not on the same side of the ray. I think.

-- 
Christopher James Huff - Personal e-mail: chr### [at] yahoocom
TAG(Technical Assistance Group) e-mail: chr### [at] tagpovrayorg
Personal Web page: http://chrishuff.dhs.org/
TAG Web page: http://tag.povray.org/


Post a reply to this message

From: Pabs
Subject: Re: Math question
Date: 11 May 2000 21:30:07
Message: <391B5EC6.7981033F@hotmail.com>
> This basically flips the number(positive to negative) if the point and
> the direction are not on the same side of the ray. I think.

THANKS - IT WORKS


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.