POV-Ray : Newsgroups : povray.programming : Spheres intersection and transformation Server Time
22 Dec 2024 07:23:51 EST (-0500)
  Spheres intersection and transformation (Message 1 to 1 of 1)  
From: Celui
Subject: Spheres intersection and transformation
Date: 3 Jun 2005 04:10:01
Message: <web.42a0101920102fd6367138710@news.povray.org>
Hello all.
I have written a small code, but I do not understand what's wrong.

Preliminary comments :
 - If there is an intersection with englobant (a virtual sphere) then
 - Try to find if there are intersection with other inside sphere
Those spheres are built by apply the (Ifs->Trans[])^-1 to englobant.
I have mathematically proved that these little spheres are inside englobant.

But instead of applying (Ifs->Trans[])^-1 to the sphere, the complexity will
be too gorgious, so I apply Ifs->Trans[] to the Ray. That gives to me
New_Ray.

if (Intersect_Sphere(Ray, englobant->Center, Sqr(englobant->Radius), Prof1,
Prof2))
{
   MY_DEBUG("Intersection with englobant");
   for(int i=0; i < Ifs->NbTrans; i++)
   {
      //Variable declaration
      RAY * New_Ray = (RAY*) malloc(sizeof(RAY));
      VECTOR * final_Point = (VECTOR *) malloc(sizeof(VECTOR));
      VECTOR * final_trans_Point = (VECTOR *) malloc(sizeof(VECTOR));
      TRANSFORM * transfo = (TRANSFORM*) malloc(sizeof(TRANSFORM));

      //Compute the transformation from the matrix
      Compute_Matrix_Transform(transfo, Ifs->TransMatrix[0]);

      //Apply the the transformation to Ray->Initial
      MTransPoint(New_Ray->Initial, Ray->Initial, transfo);

      //Apply the transformation to Ray->Initial + Ray->Direction
      VAdd(*final_Point, Ray->Initial, Ray->Direction);
      MTransPoint(*final_trans_Point, *final_Point, transfo);
      VSub(New_Ray->Direction, *final_trans_Point, New_Ray->Initial);

      //Copy the other walues of Ray
      New_Ray->Index = Ray->Index;
      New_Ray->Optimisiation_Flags = Ray->Optimisiation_Flags;
      for (int lm = 0; lm<MAX_CONTAINING_OBJECTS; lm++)
      {
        New_Ray->Interiors[lm] = Ray->Interiors[lm];
      }

      //Try the intersection with the inside sphere
      if (Intersect_Sphere(New_Ray, englobant->Center,
Sqr(englobant->Radius), Profondeur, Prof2) )
      {
        MY_DEBUG("Intersection with the inside sphere");
        return true;
      }
   }
   return false;
}


But that code doesn't work (I mean I try with the identity matrix).
It always detects the intersection with englobant but nevers finds the one
with New_Ray.

I assumed that Initial was the point where the ray is launched (typically
the camera) and direction is the ray direction ...

Please, help.me !

Celui //


Post a reply to this message

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