This topic is 3020 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hey fellows... once again I search you for guidance...

Here's the deal: I have to solve a problem for a raytracer, but I seem to be stuck...

So.. I have the sphere info. Lets suppose:

SphereCenter[3, 4, 5], and SphereRadius: 6.

How do I represent that through a quadric??

Next comes the ray/quadric collision calculation, but I believe it wont be a problem.

*apologize if thats old subject
Thank you.

##### Share on other sites
Quote:
 SphereCenter[3, 4, 5], and SphereRadius: 6.How do I represent that through a quadric??

(x-3)^2 + (y-4)^2 + (z-5)^2 = 36

##### Share on other sites
Hey there. Tx for the reply...

Well.. I dunno if I have not made myself clear... or if I'm just wrong.. but I meant, the quadric surface definition...

That is: F(x, y, z) = Ax^2 + By^2 + Cz^2 + Dxy+ Exz + Fyz + Gx + Hy + Iz + J = 0

If I have, for the sphere:

x2 + (y-5) 2 + (z+20)2 = 252

I know it shows up in the general quadric surface like:

a=1,b=1,c=1,d=0,e=0,f=0,g=0,h=-5,j=10,k=-200

but how do I get to those values? Im having a hard time to understand that...

anyone knows how to do that?

##### Share on other sites
(x-Cx)^2 + (y-Cy)^2 + (z-Cz)^2 = r^2
x^2 - 2Cx*x + Cx^2 + y^2 - 2Cy*y + Cy^2 + z^2 - 2Cz*z + Cz^2 - r^2 = 0

if F(x, y, z) = Ax^2 + By^2 + Cz^2 + Dxy+ Exz + Fyz + Gx + Hy + Iz + J = 0
A = 1
B = 1
C = 1
D = 0
E = 0
F = 0
G = -2Cx
H = -2Cy
I = -2Cz
J = Cx^2 + Cy^2 + Cz^2 - r^2

It's pretty straight forward, but I did it quick so you may want to check my math.

##### Share on other sites
Quote:
 Original post by kfboelterbut how do I get to those values? Im having a hard time to understand that...anyone knows how to do that?

 (a+b)^2 = a^2 + 2ab + b^2

Apply that formula and add the terms that go together. You can do it.

##### Share on other sites
theeeere you go Mr. Alvaro! just what I needed...
Guess my math is sucking pretty bad huh... hehe

anyway,, thank you so much! :D

##### Share on other sites
hey my friends... so there's more coming up...

well... my collision test is working fine with a sphere,, but I'm having problems with a plane... (just for the record.. i want to represent the shapes as quadric surfaces.. I know it might be better to treat them separetely)..

I have he plain
a=0.0 b=0.0 c=0.0 d=0.0 e=0.0 f=0.0 g=0.0 h=1.0 j=0.0 k=5.0

im doing the same as it's supposed, in order to check ray/quadric intersection..

*finding out t in t = b^2+or-sqrt(b*b-4*a*c)/2a

if you guys want I can show how to get a b and c coefficients....

anyway.. if I got that working with a sphere, shouldn it be working ok with planes? its detecting collisions where its not supposed to.. so I really dont know...

any help is welcome^^

##### Share on other sites
Quote:
 Original post by kfboelter*finding out t in t = b^2+or-sqrt(b*b-4*a*c)/2a

That should be t = (-b+or-sqrt(b*b-4*a*c))/(2*a)

Quote:
 if you guys want I can show how to get a b and c coefficients....

No, I can figure it out myself.

Quote:
 anyway.. if I got that working with a sphere, shouldn it be working ok with planes?

No, you can't divide by 0.

##### Share on other sites
hey there alvaro^^

thks again..
so, you were right bout the "t" formula... I miss typed...

howevere,, there is no division by 0...
here's how I get a, b and c coefs...

acoef = 2 * f * dx * dz + 2 * e * dy * dz + c * dz * dz + b * dy * dy +
a * dx * dx + 2 * d * dx * dy ;

bcoef = 2 * b * y0 * dy + 2 * a * x0 * dx + 2 * c * z0 * dz +
2 * h * dy + 2 * g * dx + 2 * j * dz + 2 * d * x0 * dy +
2 * e * y0 * dz + 2 * e * z0 * dy + 2 * d * y0 * dx +
2 * f * x0 * dz + 2 * f * z0 * dx;

ccoef = a * x0 * x0 + 2 * g * x0 + 2 * f * x0 * z0 + b * y0 * y0 +
2 * e * y0 * z0 + 2 * d * x0 * y0 + c * z0 * z0 + 2 * h * y0 +
2 * j * z0 + k ;

and also important to mention..

<code>
if (acoef == 0)
{
if (bcoef == 0)
{
return -1;
}
t = -ccoef/bcoef;
return t;
}
</code>

so no division by 0 there...
I thought a quadric representation of a surface is a generic way of dealing with the object.. really don't know whatsgoing on

##### Share on other sites
Quote:
 Original post by kfboelterI have he plaina=0.0 b=0.0 c=0.0 d=0.0 e=0.0 f=0.0 g=0.0 h=1.0 j=0.0 k=5.0

Quote:
 Original post by kfboelterhowevere,, there is no division by 0...

So a is 0.0, and you are dividing by 2*a. How is that not dividing by zero?

1. 1
2. 2
3. 3
Rutin
15
4. 4
khawk
14
5. 5
frob
12

• 9
• 11
• 11
• 23
• 12
• ### Forum Statistics

• Total Topics
633661
• Total Posts
3013220
×