Discussion about math, puzzles, games and fun. Useful symbols: ÷ × ½ √ ∞ ≠ ≤ ≥ ≈ ⇒ ± ∈ Δ θ ∴ ∑ ∫ π -¹ ² ³ °

You are not logged in.

- Topics: Active | Unanswered

**luca-deltodesco****Member**- Registered: 2006-05-05
- Posts: 1,470

im trying to add tori into my ray tracer (among other quartic shapes) but atm im just concentrating on tori, but im having troubles in both the quartic equation that has to be solved, and in solving the quartic itself, im using ferraris method as described on wikipedia, but it doesnt seem to work (my complex math is right, im pretty sure of that)

as for the quartic equation itself, ive went through it about 4 times, and i always get to the same set of coeffecients, but when comparing with the expanded torus equation, the values never seem to be exactly the same, even after taking into account round off error from computations

http://delta.ecwhost.com/TORUS.html

http://en.wikipedia.org/wiki/Quartic_equation

and my complex math:

a*b = (a.x*b.x - a.y*b.y) + i(a.x*b.y + a.y*b.x)

let d = |b|^2

a/b = (a.x*b.x + a.y*b.y)/d + i(a.y*b.x - a.x*b.y)/d

arg(a) = atan2(a.y,a.x); // from c/c++ math header

let b = sqrt(sqrt(a.x*a.x + a.y*a.y)); // i.e. |a|^(1/2)

let c = arg(a)/2

sqrt(a) = b.cos(c) + i.b.sin(c)

ln(a) = ln(|a|) + i.arg(a)

let b = e^(a.x)

e^(a) = b.cos(a.y) + i.b.sin(a.y)

a^(1/3) = e^(ln(a)/3)

*Last edited by luca-deltodesco (2006-05-05 20:10:07)*

The Beginning Of All Things To End.

The End Of All Things To Come.

Offline

**krassi_holmz****Real Member**- Registered: 2005-12-02
- Posts: 1,905

i : cos(t)(m+cos(u));

ii : sin(t)(m+sin(u));

iii : sin(u)

for t,u from 0 to 2Pi

IPBLE: Increasing Performance By Lowering Expectations.

Offline

**luca-deltodesco****Member**- Registered: 2006-05-05
- Posts: 1,470

krassi_holmz wrote:

i : cos(t)(m+cos(u));

ii : sin(t)(m+sin(u));

iii : sin(u)

for t,u from 0 to 2Pi

what has that got to do with anything ive said, or about the links i posted at all? Did you read anything i said?

i Did say, RAY-torus intersections, not: what are the parametric equations for a torus

by 't' i meant, t from the ray equation a[t] = a[0] + tv, which i explained about the first problem in the first link, i put it onto that webpage, because it was easier for me to right it out in html and put it on my site, than posting it all here since i dont know all the things for the [math] tags to be able to have subscript etc, and you cant have different sized and coloured text here

*Last edited by luca-deltodesco (2006-05-05 20:12:21)*

The Beginning Of All Things To End.

The End Of All Things To Come.

Offline

**MathsIsFun****Administrator**- Registered: 2005-01-21
- Posts: 7,630

Welcome to the forum luca-deltodesco!

Sorry I am not directly answering your question luca, just talking about forum features. But subscripts and superscripts can be achieved by using the "sub" and "sup" tags:

M[sub]a[/sub]=x[sup]e[/sup]

`M[sub]a[/sub]=x[sup]e[/sup]`

And colors can also be achieved, have a read here: http://www.mathsisfun.com/forum/viewtopic.php?id=2892

And a special feature of our use of the math tag: click on the image and a screen will pop up showing you the latex code used. Try clicking on this:

It certainly looks like you are immersed in some heavy coding. Can you tell us more about your ray-tracer?

(BTW: give krassi a chance, he has solved some tricky problems before)

"The physicists defer only to mathematicians, and the mathematicians defer only to God ..." - Leon M. Lederman

Offline

**Patrick****Real Member**- Registered: 2006-02-24
- Posts: 1,005

if you wonna do sub/sup with the math-tag.., to me it's easier than the [sup] and [sub] tags, because if you're writing more than one sup or sub you only have to write a _ or ^(with {} after them for a+b fx)

*Last edited by Patrick (2006-05-05 23:34:02)*

Support MathsIsFun.com by clicking on the banners.

What music do I listen to? Clicky click

Offline

**luca-deltodesco****Member**- Registered: 2006-05-05
- Posts: 1,470

MathsIsFun wrote:

It certainly looks like you are immersed in some heavy coding. Can you tell us more about your ray-tracer?

well, its the third one im building, i started with a very simple one having only reflections, spheres, ellipsoids and planes

then another smaller one that had full camera and transformations for the primitaves

the new one im making is a MASSIVE advancement on it, along with a full GUI im creating for it to encapsulate all its tools

this one will have spheres,planes,cones,tori,cylinders,capsules (all rotateable and scalable) (all with textures, normal mapping, refraction maps, reflection maps (i.e. you can have a sphere with a procedurally generated fractal texture, with the same texture renderered in grey scale for a reflection map so that the white parts will reflect all light, and the black parts reflect no light, with a heightmap converted to a normal map for normal mapping to give it a 3d look, with a refraction map opposite to the reflectoin map so that the black parts on the reflection map would allow all light to pass through and be refractad))

along with a generic quadric and quartic shape primitave, along with procedurally generated Julia quaternion fractals (along with other types) and procedural 3d Perlin noise clouds/solids along with 3d procedural textures)

along with CSG so that you can have a sphere with a torus cut out of it to give a round indent on the sphere) along with convex polygons.

along with 3d heightmap terrain, using another type of texture of colour which holds data for each vertex of the percentages of each 8 textures per heightmap texture to be used at that vertex)

and if i learn it, photon mapping. Also fuzzy reflections (i.e. multiple rays cast out to give appearance of noise at a very low level) which i might use for 'fake' photon mapping to scatter rays of light from a scenario when light would be absorbed to give atleast some sort of real ambient lighting in reverse.

Tori, especcialy from the quartics is very important i feel, since using CSG, you can make mega complex shapes, using spheres, toruses, planes and cylinders.

I have already written in a seperate c++ program, a compiler that takes a scene file, containing a function based language to set up the scene that parses and converts it to a binary .drt file read by the renderer which will save a .bmp of the rendering to the given directory

a pretty BIG project, but its constantly challenging me in ways of maths, programming and algorithmics so its never a bore and since ive started ive pretty much learnt/figured out most of what ive just written above (id already written programs in the past to create fractals and quaternion renderings, but never ray traced or included in a ray tracing package)

this is all alongside my GCSE and A-Level exams (GCSE + A-Level Maths of which im studying 2 years early)

ANYWAYS, in terms of the toruses

rays are cast out from the camera in its system, then transformed and translated to world system, then translated and transformed into the objects base system so that the object is always at the centre, un rotated and un scaled so that the intersections can be found with far less complex math, and then intersection point and normal to surface at the point are un-transformed and un-translated back into world space

The Beginning Of All Things To End.

The End Of All Things To Come.

Offline

**davidross18101987****Guest**

i think you will find its "tori" *

**luca-deltodesco****Member**- Registered: 2006-05-05
- Posts: 1,470

davidross18101987 wrote:

i think you will find its "tori" *

i did say tori everywhere else, only on the last part i said toruses

The Beginning Of All Things To End.

The End Of All Things To Come.

Offline

**MathsIsFun****Administrator**- Registered: 2005-01-21
- Posts: 7,630

Well, luca, people are obviously reading about this, just no solutions

"The physicists defer only to mathematicians, and the mathematicians defer only to God ..." - Leon M. Lederman

Offline

**davidross18101987****Guest**

sorry, i see you did, i take that back

**luca-deltodesco****Member**- Registered: 2006-05-05
- Posts: 1,470

well i found one last error in my quartic coeffecients, and ive tested it out by finding a coordinate on the torus via the parametric equations and given a vector and a calculated value for 't' found the value of the quartic, for a point on the torus, the value of the quartic is < 1 * 10^(-4), and i tried increment 't' by a small amount like 0.001 and the value suddenly jumped up to >1*10^6

so it deffinately seems to be correct now

(my mistake was in the t coeffecient, i had 2(av)(2|a|^2+ R^2 - r^2), where it should have been 4(av)(|a|^2+ R^2 - r^2) )

however, i did a bit of looking on the internet, and it seems the general solution for a quartic is very numericaly unstable, which i seem to have found out on my own, so im thinking of other ways to go about solving it, the only way ive seen is a recursive algorithm to find the roots by basicly subdividing a search area between randomely selected values, until a value is found that the quartic is less than a given range

but if someone get find a numericaly stable method of solving a quartic, itd be much appreciated

The Beginning Of All Things To End.

The End Of All Things To Come.

Offline

**luca-deltodesco****Member**- Registered: 2006-05-05
- Posts: 1,470

http://img353.imageshack.us/my.php?image=testsubdivide7hr.swf

theres something i made to test my recursive root finder

the function takes a min and max for the x values, and the number of sub division to do

from there it will divide the gap between min and max in 2, and then for each half, divide again, then for each quarter, divided again until the number of sub divisions has been met, then once it has, if the y-coordiante of the left and right are on opposite sides of the x-axis the middle of this is taken as the root, its not perfect. but as you can see (this is using 8 sub divisions) it works quite nicely (although for proper accuracy, since these graphs are being scaled by 1/100000000, you need to use +20 sub divisions)

the number of y coordinates found from the quartic equation is 1 + 2^n, n being the number of sub divisions, so here, the number of y coordinates found is 257, which seems quite a lot, but it runs quite fast. Theres always ways i could improve this, like by assuming that if the y coordiantes of each side of the sub division are both massive or both tiny, that there wont be a root inbetween, but that might lead to roots not being found all the time

this is actually finding the roots of a ray-torus intersection aswell so it seems ot be working alltohugh i havnt ported to C++ to test it properly in rendering

----------

http://img114.imageshack.us/img114/7161/testtorus0et.jpg

all be it badly textured with no shading, atleast it has seemingly ray traced correctly, i have also tried where the tube radius is more than the ring radius and you get the sphere with the inward spikes at the poles

*Last edited by luca-deltodesco (2006-05-23 11:04:51)*

The Beginning Of All Things To End.

The End Of All Things To Come.

Offline

**MathsIsFun****Administrator**- Registered: 2005-01-21
- Posts: 7,630

I understand the principle of the binary root finder, but the flash animation doesn't make sense to me.

The torus looks great - excited to see it with shading.

I am a user of POV-Ray, but many times I find myself going through the "change a value, see the result" loop (you know: 1.2? no. 1.3? no. 1.4? no.) trying to get it right, and I really wish I could just click and drag the shape (or the lights).

So, will your ray-tracer allow this?

"The physicists defer only to mathematicians, and the mathematicians defer only to God ..." - Leon M. Lederman

Offline

**luca-deltodesco****Member**- Registered: 2006-05-05
- Posts: 1,470

MathsIsFun wrote:

I understand the principle of the binary root finder, but the flash animation doesn't make sense to me.

The torus looks great - excited to see it with shading.

I am a user of POV-Ray, but many times I find myself going through the "change a value, see the result" loop (you know: 1.2? no. 1.3? no. 1.4? no.) trying to get it right, and I really wish I could just click and drag the shape (or the lights).

So, will your ray-tracer allow this?

well, im not so sure about that, via ray tracing, id say deffinately not since it can take depending on the scene seconds or days to render a scene, the only i could see that happening is to have the editing enviroment have a traditional scan line rendered scene aswell that you can edit visually. But thats along way away Although ill deffinately think about it

to the flash application, what its actually doing, is generating the quartic function of a ray-torus intersection, and then just graphing it, finding the roots and displaying them via the blue vertical lines (did you click it to regenerate?)

http://img60.imageshack.us/img60/4500/showsub7da.gif

that is sort of showing what the sub division thingy is doing

it takes the xmin and xmax and finds the y values

it then splits this in two calling the same function with xmin and the mid of xmin and xmax, and then with the mid of xmin and xmax with xmax so that it then calls the function for each half, and then keeps repeating so it then cuts to quarters, then eights, then 16ths, until the number of sub divions has reached the max. Which in the case is 3

so once the number of sub divisions is the desired, in this case 3, it tests the y-coordiantes, and if they are on opposite sides of the x-axis, uses the mid of the two x values as the root, so you can see in the image that in this case, with just 3 sub divisions, the 2 roots on the right are quite accurate, but not the one on the left, if you increased the number of sub divisions, the roots become more and more accurate

infact, i had it so stuck in my head to use a recursion method, that i can probably just make it run faster by just calculating the x-increment needed, and just looping from xmin to xmax, but nevermind

the good thing about this method, is that i can maybe make some culls to the sub divions, like if the y values are very large and on the same side, depending on the current sub division, stop sub dividing for that sector because its very likely there wont be a root or something

*Last edited by luca-deltodesco (2006-05-24 03:56:12)*

The Beginning Of All Things To End.

The End Of All Things To Come.

Offline