POV-Ray : Newsgroups : povray.newusers : Shoot a ray at a mesh Server Time
24 Dec 2024 11:05:22 EST (-0500)
  Shoot a ray at a mesh (Message 1 to 10 of 14)  
Goto Latest 10 Messages Next 4 Messages >>>
From: daviddoria
Subject: Shoot a ray at a mesh
Date: 6 Jun 2008 16:50:00
Message: <web.4849a25ff5d589ac145cec320@news.povray.org>
I have a mesh (list of vertices - .obj type of file) that i would like to shoot
a ray at from a particular point and see if it hits the mesh, and if it does,
get the coordinates of the intersection.  Is this possible to do with pov ray?
Can someone point me to an example that does something like this? Does pov ray
have its own scripting language or will I have to dig through the source code
to do this task?

Thanks,

Dave


Post a reply to this message

From: Stephen
Subject: Re: Shoot a ray at a mesh
Date: 6 Jun 2008 17:20:50
Message: <vgaj44ttm01p9aahtugnph2q5gqamhe7ml@4ax.com>
On Fri,  6 Jun 2008 16:47:27 EDT, "daviddoria" <nomail@nomail> wrote:

>I have a mesh (list of vertices - .obj type of file) that i would like to shoot
>a ray at from a particular point and see if it hits the mesh, and if it does,
>get the coordinates of the intersection.  Is this possible to do with pov ray?
>Can someone point me to an example that does something like this? Does pov ray
>have its own scripting language or will I have to dig through the source code
>to do this task?
>
Welcome Dave,
	What you want to do is possible. Look in the documentation for
trace, but be warned (gently) that this is an advanced feature. I am
sure someone better versed in Pov-Ray SDL can answer you better. 
As for a scripting language you are in luck, Pov-Ray's scripting
language is called SDL, see the document section 3.2  Scene
Description Language and have a look at the tutorial 2.3.10  SDL
tutorial: A raytracer.
Are you using a modeller to create your scene? And if so it is a very
good idea to stop for a moment to become familiar with SDL.
-- 

Regards
     Stephen


Post a reply to this message

From: Chris B
Subject: Re: Shoot a ray at a mesh
Date: 6 Jun 2008 17:45:03
Message: <4849afdf$1@news.povray.org>
"daviddoria" <nomail@nomail> wrote in message 
news:web.4849a25ff5d589ac145cec320@news.povray.org...
>I have a mesh (list of vertices - .obj type of file) that i would like to 
>shoot
> a ray at from a particular point and see if it hits the mesh, and if it 
> does,
> get the coordinates of the intersection.  Is this possible to do with pov 
> ray?
> Can someone point me to an example that does something like this? Does pov 
> ray
> have its own scripting language or will I have to dig through the source 
> code
> to do this task?
>
> Thanks,
>
> Dave
>

You'd need to convert it into a POV-Ray mesh which can be done using 
PoseRay.
You can then wrap the mesh definition in an object declaration using 
#declare to give it a name, then you can pass this into the 'trace' function 
along with the start point and a direction vector for the line you want to 
trace. This will return the coordinates of the point of intersection.

You should also pass the optional last parameter in which will be set to the 
normal at the point of intersection. You can then test the value and if it 
has a zero length, the ray didn't hit the object.

Your SDL would look something like this, assuming that the file 
'YourMeshFile.inc' contains the mesh definition generated using PoseRay and 
wrapped in a  #declare statement to give it the name 'MyMesh':

#include "YourMeshFile.inc"
#declare MyNormal = <0,0,0>;
#declare MyStart = <1, 1, 1>;
#declare MyDirection =  <0, 0, 0> - MyStart;
#declare MyIntersection =   trace ( MyMesh, MyStart, MyDirection, MyNormal);
#if (vlength(MyNormal)=0)
  ...  // What to do if the ray missed the object
#else
  ... // What to do if the ray hit the object
#end

Of course you then need to decide what you're going to do with the 
information. e.g. write the coordinates out to the debug stream or to a 
file, or display a scene with a sphere at the point of intersection.

Regards,
Chris B


Post a reply to this message

From: daviddoria
Subject: Re: Shoot a ray at a mesh
Date: 6 Jun 2008 22:05:01
Message: <web.4849ebdb784caf0d145cec320@news.povray.org>
Thanks for the quick responses!  It sounds like using POV ray for this may be
overkill? Is there an easier approach that someone can recommend? It seems like
it should be possible to shoot rays at a model without converting it to a POV
ray scene (of course not with POV ray though haha!).

If not, is there some linux equivalent of pose ray?

Thanks,

Dave


Post a reply to this message

From: Warp
Subject: Re: Shoot a ray at a mesh
Date: 7 Jun 2008 03:19:51
Message: <484a3697@news.povray.org>
daviddoria <nomail@nomail> wrote:
> It sounds like using POV ray for this may be overkill?

  Why would it be overkill? It sounds to me like the easiest way by far.

-- 
                                                          - Warp


Post a reply to this message

From: Stephen
Subject: Re: Shoot a ray at a mesh
Date: 7 Jun 2008 03:35:01
Message: <ueek44dp2hf8892fs5396jtk55cspaeubv@4ax.com>
On Fri,  6 Jun 2008 22:00:59 EDT, "daviddoria" <nomail@nomail> wrote:

>Thanks for the quick responses!  It sounds like using POV ray for this may be
>overkill? Is there an easier approach that someone can recommend? It seems like
>it should be possible to shoot rays at a model without converting it to a POV
>ray scene (of course not with POV ray though haha!).

This newsgroup tends to be inhabited by PovRay fanatics so you might
not get a suitable reply. For us using PovRay is goal in its own
right. :)

>If not, is there some linux equivalent of pose ray?
>

I believe that you can run PoseRay under Wine.
-- 

Regards
     Stephen


Post a reply to this message

From: Chris B
Subject: Re: Shoot a ray at a mesh
Date: 7 Jun 2008 03:36:25
Message: <484a3a79$1@news.povray.org>
"daviddoria" <nomail@nomail> wrote in message 
news:web.4849ebdb784caf0d145cec320@news.povray.org...
> Thanks for the quick responses!  It sounds like using POV ray for this may 
> be
> overkill? Is there an easier approach that someone can recommend? It seems 
> like
> it should be possible to shoot rays at a model without converting it to a 
> POV
> ray scene (of course not with POV ray though haha!).
>

Whether there's an easier approach depends largely on where you're starting 
from and where you're going with this.

If you're developing an application that reads the obj file you may find it 
easiest to use the application code examples outlined at the following URL:
http://www.codeproject.com/KB/graphics/Simple_Ray_Tracing_in_C_2.aspx?display=Print

If you're using a particular modeller to generate or process the obj file, 
then that modeller may provide something that can perform that sort of 
calculation for you. Various modellers now support their own form of 
scripting.

If you're a dab hand at Perl scripting then you might find it easiest to 
read the vertices of the triangles directly from the obj file (it's just a 
plain ASCII file) and calculate the intersection point triangle by triangle. 
If the line intercepts multiple triangles you just keep track of the one 
closest to your start point.

> If not, is there some linux equivalent of pose ray?

According to the announcement at 
http://news.povray.org/povray.news-submissions/thread/%3C451a0953@news.povray.org%3E/?ttop=274065&toff=50

you can run PoseRay on Linux using Wine 0.9.21.

Regards,
Chris B.


Post a reply to this message

From: Kenneth
Subject: Re: Shoot a ray at a mesh
Date: 7 Jun 2008 13:10:01
Message: <web.484abf7e784caf0d78dcad930@news.povray.org>
"Chris B" <nom### [at] nomailcom> wrote:
> "daviddoria" <nomail@nomail> wrote in message
> news:web.4849a25ff5d589ac145cec320@news.povray.org...

> #declare MyStart = <1, 1, 1>;
> #declare MyDirection =  <0, 0, 0> - MyStart;

The resulting MyDirection vector in this case would be <-1,-1,-1>...kind of an
odd direction in which to shoot a trace ray, *assuming* that the mesh occupies
some area on an x/z plane...i.e., horizontal. Far better would be to shoot the
trace ray straight 'down.'

Let's assume that the mesh extends from <0,0,0> to <1,0,1>--like a POV-Ray
height_field. Would it not be better to say
#declare MyStart =
<*some value between 0 and 1*,100,*some value between 0 and 1*>; // y is just an
// arbitrary large number, to place it well above the mesh

#declare MyDirection = <0,-1,0>; // pointing straight down

OR
#declare MyDirection = <0,0,0> - <0, MyStart.y,0>; // using dot notation to pick
// one value out of a vector

OR
#declare MyDirection = <0, -MyStart.y,0>;

These three MyDirection's all all equivalent...but <0,-1,0> is far easier to
write!

Ken W.


Post a reply to this message

From: Chris B
Subject: Re: Shoot a ray at a mesh
Date: 7 Jun 2008 13:19:53
Message: <484ac339@news.povray.org>
"Kenneth" <kdw### [at] earthlinknet> wrote in message 
news:web.484abf7e784caf0d78dcad930@news.povray.org...
> "Chris B" <nom### [at] nomailcom> wrote:
>> "daviddoria" <nomail@nomail> wrote in message
>> news:web.4849a25ff5d589ac145cec320@news.povray.org...
>
>> #declare MyStart = <1, 1, 1>;
>> #declare MyDirection =  <0, 0, 0> - MyStart;
>
> The resulting MyDirection vector in this case would be <-1,-1,-1>...kind 
> of an
> odd direction in which to shoot a trace ray, *assuming* that the mesh 
> occupies
> some area on an x/z plane...i.e., horizontal. Far better would be to shoot 
> the
> trace ray straight 'down.'
>
> Let's assume that the mesh extends from <0,0,0> to <1,0,1>--like a POV-Ray
> height_field. Would it not be better to say
> #declare MyStart =
> <*some value between 0 and 1*,100,*some value between 0 and 1*>; // y is 
> just an
> // arbitrary large number, to place it well above the mesh
>
> #declare MyDirection = <0,-1,0>; // pointing straight down
>
> OR
> #declare MyDirection = <0,0,0> - <0, MyStart.y,0>; // using dot notation 
> to pick
> // one value out of a vector
>
> OR
> #declare MyDirection = <0, -MyStart.y,0>;
>
> These three MyDirection's all all equivalent...but <0,-1,0> is far easier 
> to
> write!
>
> Ken W.
>

Yes probably. I just adapted the example from the help. I assumed from his 
question that Dave would know the particular point that he wanted to shoot 
the ray from and the direction he wanted to shoot it in.

Regards,
Chris B.


Post a reply to this message

From: Kenneth
Subject: Re: Shoot a ray at a mesh
Date: 7 Jun 2008 23:15:00
Message: <web.484b4a43784caf0d78dcad930@news.povray.org>
"Chris B" <nom### [at] nomailcom> wrote:

>
> Yes probably. I just adapted the example from the help. I assumed from his
> question that Dave would know the particular point that he wanted to shoot
> the ray from and the direction he wanted to shoot it in.
>

Ah yes, I see what you mean.  It does make sense, when tracing a sphere.

I do feel sorry for new users trying to make sense of the trace operation, given
the short and somewhat perfunctory explanation of it. It's such a powerful
feature of POV-Ray! But some of the documentation just isn't as clear as it
should be.

For example, although the docs state--in a roundabout way--that the
optional 4th parameter (the found 'normal' at the object's surface) has to have
it's vector pre-#declared before it can be used in the trace operation, and
gives <0,0,0> as an example, in fact it can be any arbitrary vector
value...like <26,-38,1.0046>. It's only a 'place-holder' which will be filled
with REAL values as soon as trace shoots a ray at the object surface. SO...
trace can actually return TWO values, the intersection point and the normal at
that point...both vectors, and both requiring a #declare. Another item of
confusion: Somewhere above the trace explanation, it says, "The following are
the functions which return vector values."  The important word being RETURN.
But there are other functions following trace that actually DON'T return any
value (vnormalize being one.) Pity the poor new user trying to understand all
of this!

Speaking of vnormalize: The 'normal' vector found at the surface during a trace
is automatically 'normalized' to be one unit in length.  This is how the trace
example uses it to make a cylinder sticking out from the surface of the sphere.

Ken W.


Post a reply to this message

Goto Latest 10 Messages Next 4 Messages >>>

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