POV-Ray : Newsgroups : povray.general : queston for the math wizards... Server Time
18 Nov 2024 23:36:49 EST (-0500)
  queston for the math wizards... (Message 1 to 6 of 6)  
From: Dan Byers
Subject: queston for the math wizards...
Date: 11 Jul 2002 20:29:18
Message: <B9538BA3.D181%goofygrafx@aol.com>
http://hometown.aol.com/goofygrafx/qa.html

I'd post the question and associated images here, but last time I posted a
binary file in this NG I got verbally slapped about.  Anyway, any help is
appreciated.  

-- 
dan
http://hometown.aol.com/goofygrafx


Post a reply to this message

From: Slime
Subject: Re: queston for the math wizards...
Date: 11 Jul 2002 21:38:12
Message: <3d2e3304@news.povray.org>
1. The equation of a line can be expressed as y-k = m*(x-h). m is the slope
of the line (rise/run), and (h,k) is a point on the line.

One point on the line is (2,2). So we'll use 2 for h and k.
The slope of the line is 5/4. (look at your picture, you can see the line
goes up 5 and to the right 4, so we take the rise over the run.)

So the equation of the first line is y-2 = 5/4*(x-2).

The equatoin of the second line is, of course, y=5, since it consists of all
points where y = 5.

The intersection between them can be found easily, since we know that at the
intersection, y=5, and can just plug that into the equation for the other
line:

5-2 = 5/4*(x-2)
3*4/5 = x-2
12/5+2 = x

So the intersection must be at (12/5+2, 5). (You can work out 12/5+2 on your
own =)

2. This one is more difficult. I know from experience that we're going to
end up with a quadratic equation to solve (an equation where the highest
exponent of y or x is two.)

Again, it's a matter of taking the equations of both shapes and finding the
(x,y) values where both of them are true.

The equation of a circle of radius r, centered at (h,k), is (x-h)^2 +
(y-k)^2 = r^2. This is based on pythagorean's theorem.

The equation of this particular circle, therefore, is (x-5)^2 + (y-5)^2 =
4^2.
The equation of the line is y=3.

Again, we can merely substitute 3 in for y in the circle's equation.

(x-5)^2 + (3-5)^2 = 4^2
x^2-10*x+25 + (-2)^2 = 16
x^2 - 10*x + 9 + 4 = 0
x^2 - 10*x + 13 = 0

Heh, it's a quadratic, as I expected. (If you recall, quadratic equations
have either zero, one, or two solutions. In this case, that will correspond
to the line missing the circle entirely, skimming just along its edge, or
intersecting twice. In this case, we can see that it's intersecting twice.)

We'll use the quadratic equation:

x = (-b +/- sqrt(b^2 - 4*a*c))/(2*a)

(Now, if you're not certain that the line will intersect the sphere, then
what you need to do is check (b^2 - 4*a*c). If that is less than zero, then
you'll have a negative inside the square root - which means there is no
solution, and therefore no intersection. If it's equal to zero, then there
will be exactly one solution - the line skims across the edge of the sphere.
And if it's greater than zero, then the +/- takes effect, and we have two
solutions: two intersections.)

Let's substitute our values in:

x = (10 +/- sqrt(100 - 4*1*13))/(2*1)
x = 5 +/- sqrt(48)/2

The square root of 48 is something that you can leave for POV-Ray to work
out.

Now, if you plan on doing this calculation many different times, then you
should do it not with numbers, but rather with variables, out on paper (the
variables would be the slope and x and y values of a point on the line, the
x and y values of the center of the circle, and the radius of the circle. be
sure to give them all separate names that don't include "x", "y", or "z" so
that you don't get confused.). Then find the solution in terms of the
variables, and you'll come up with a single equation that you can type into
povray to easily find the intersections given the variables.

I commend you on your desire to know how to do these without the use of the
trace() function. It will get you farther in the long run.

 - Slime
[ http://www.slimeland.com/ ]


Post a reply to this message

From: Dan Byers
Subject: Re: queston for the math wizards...
Date: 11 Jul 2002 21:53:24
Message: <B9539F5A.D358%goofygrafx@aol.com>
in article 3d2e3304@news.povray.org, Slime at slm### [at] slimelandcom wrote on
7/11/02 8:36 PM:

<snip>
 
> Now, if you plan on doing this calculation many different times, then you
> should do it not with numbers, but rather with variables, out on paper (the
> variables would be the slope and x and y values of a point on the line, the
> x and y values of the center of the circle, and the radius of the circle. be
> sure to give them all separate names that don't include "x", "y", or "z" so
> that you don't get confused.). Then find the solution in terms of the
> variables, and you'll come up with a single equation that you can type into
> povray to easily find the intersections given the variables.
> 

that was the plan all along - I want to incorporate it into the macro
include file I'm working on for my blobs :)

> I commend you on your desire to know how to do these without the use of the
> trace() function. It will get you farther in the long run.
> 
> - Slime
> [ http://www.slimeland.com/ ]
> 
> 

more of a necessity, actually - most of the POVing I do, I do at work using
v. 3.1 for DOS (d'oh!).. believe me, if I could use trace(), I would!  :)

again, thanks a bunch!  I now have something interesting to work on this
weekend... :)

-- 
dan
http://hometown.aol.com/goofygrafx


Post a reply to this message

From: Slime
Subject: Re: queston for the math wizards...
Date: 11 Jul 2002 22:07:43
Message: <3d2e39ef@news.povray.org>
> that was the plan all along - I want to incorporate it into the macro
> include file I'm working on for my blobs :)


Interesting, what does it do?

> > I commend you on your desire to know how to do these without the use of
the
> > trace() function. It will get you farther in the long run.
>
> more of a necessity, actually - most of the POVing I do, I do at work
using
> v. 3.1 for DOS (d'oh!).. believe me, if I could use trace(), I would!  :)

Well, the reason I say that is because the experience will be necessary in
the future, when you come across more difficult problems that trace() is
unable to solve. (For instance, if you have two spheres' initial positions
and velocities, at what time will they collide? That can't be solved with
trace, because both objects are moving.)

IMO, trace() should be used only in cases where a mathematical solution is
impossible or impractical, like finding the intersection of a line with an
isosurface based on the random noise function.

 - Slime
[ http://www.slimeland.com/ ]


Post a reply to this message

From: Dan Byers
Subject: Re: queston for the math wizards...
Date: 11 Jul 2002 22:33:29
Message: <B953A8BE.D35D%goofygrafx@aol.com>
in article 3d2e39ef@news.povray.org, Slime at slm### [at] slimelandcom wrote on
7/11/02 9:05 PM:

>> that was the plan all along - I want to incorporate it into the macro
>> include file I'm working on for my blobs :)
> 
> 
> Interesting, what does it do?
> 

when it's done, it will let me use blobs like brush strokes... curved lines,
straight lines, zigzags, all kinds of weird stuff like that... my gallery
page has a couple of examples of the kinds of blob images I'm doing, and
this file will help speed things up a bit... whether it will be useful to
anyone else, I don't know...

dan


Post a reply to this message

From: Tor Olav Kristensen
Subject: Re: queston for the math wizards...
Date: 12 Jul 2002 20:06:51
Message: <3D2F6D9F.8230FC9D@hotmail.com>
Dan Byers wrote:
> 
> http://hometown.aol.com/goofygrafx/qa.html
> 
> I'd post the question and associated images here, but last time I posted a
> binary file in this NG I got verbally slapped about.  Anyway, any help is
> appreciated.

Dan,

I think the PlaneToLineSegment() macro in the code below will
solve your problem. The rest of the code illustrates the problem
and shows the solution.

The macro can solve a more general problem in 3D space too.
(See comment above macro.)

I do not really understand why the colors of the cylinder grid
"shines through" in some regions. Can anyone explain this ?


Tor Olav


// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7
// Copyright 2002 by Tor Olav Kristensen
// Email: t o r _ o l a v _ k [ a t ] h o t m a i l . c o m
// http://hjem.sol.no/t-o-k/povray
// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7

#version 3.5;

#include "colors.inc"

default { texture { finish { ambient White*0.8 } } }

// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7

background { color Gray30 }

camera {
  orthographic
  location 5*x + 5*y - 10*z
}


// Show coordinate grid

union {
  #local Cnt = 0;
  #while (Cnt <= 10)
    cylinder { 0*x, 10*x, 0.03 translate Cnt*y }
    cylinder { 0*y, 10*y, 0.03 translate Cnt*x }
    #local Cnt = Cnt + 1;
  #end // while
  pigment { color Yellow } 
}

// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7
// Macro to find the closest point in a line segment to a plane

#macro PlaneToLineSegment(pPlane, vPlane, p1Line, p2Line)

  #local vLine = p2Line - p1Line;
  #local S = vdot(pPlane - p1Line, vPlane)/vdot(vLine, vPlane);

  (p1Line + max(0, min(S, 1))*vLine)

#end // macro PlaneToLineSegment


#declare HLT = 0.08; // Half of the line thickness


// Define a line segment

#declare pA = 2*x + 2*y;
#declare pB = 6*x + 7*y;

union {
  cylinder { pA, pB, HLT }
  sphere { pA, HLT*2 }
  sphere { pB, HLT*2 }
  pigment { color Red }
}


// Define another "line"

#declare pPl = y*5; // A point in plane
#declare vPl = y; // A normal vector for plane
//#declare vPl = vPl + x/5; // Make it a different "line"

union {
  cylinder {
    -vPl*HLT, vPl*HLT, 12
    translate pPl
  }
  sphere { pPl, HLT*2 }
  pigment { color Magenta/2 + Blue/3 }
}


// Find intersection of line segment and other "line"

#declare pIntersect = PlaneToLineSegment(pPl, vPl, pA, pB);

sphere { pIntersect, HLT*2.5 pigment { color White*2 } }

// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7


Post a reply to this message

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