POV-Ray : Newsgroups : povray.general : Algebra in Pov-Ray Server Time
24 Dec 2024 13:15:24 EST (-0500)
  Algebra in Pov-Ray (Message 1 to 3 of 3)  
From: Nekar
Subject: Algebra in Pov-Ray
Date: 27 Jul 2006 07:35:35
Message: <44c8a507@news.povray.org>
How can i do this in Pov?

A)  x=2*y + 1
B) y= x-1

...substitute y's values
x=(2*(x-1))+1
x=(2*x) - 2 + 1
x=(2*x) -1
x-(2*x)=-1
-x=-1
x=1

.. and vice-versa
y=(2*y)+1-1
y=(2*y)
y-(2*y)=0
-y=0
y=0

Is this possible with Pov?

Can it be taken further to stuff like

y=(x*x*x) - (z*z) + 3

... etc


It could be very usefull for checking intersection of objects imo


-- 
-Nekar Xenos
"The truth is out there"


Post a reply to this message

From: Mike Williams
Subject: Re: Algebra in Pov-Ray
Date: 27 Jul 2006 08:09:20
Message: <z9F$AAAjyKyEFwfu@econym.demon.co.uk>
Wasn't it Nekar who wrote:
>How can i do this in Pov?
>
>A)  x=2*y + 1
>B) y= x-1

Just to start the ball rolling, but with no expectation of it being a
very practical solution: 

You can set up two functions

#declare fx = function(y){2*y+1}
#declare fy = function(x){x-1}

Then this surface evaluates to a plane which has its x coordinate equal
to the solution.
                   
isosurface {
  function {x-fx(fy(x))} open
  contained_by {box{-3,3}}
  max_gradient 3
  pigment {rgb 1}
}  

You can then trace() that isosurface to obtain the solution for x, then
obtain the y solution from

  #declare y_solution = fy(x_solution);


If your original functions are non-linear, then you can get multiple
planes in the output, one plane for each x_solution.


Unfortunately you won't know how to choose a suitable contained_by
object or max_gradient beforehand.

-- 
Mike Williams
Gentleman of Leisure


Post a reply to this message

From: Tim Attwood
Subject: Re: Algebra in Pov-Ray
Date: 27 Jul 2006 18:09:41
Message: <44c939a5@news.povray.org>
Straight lines will cross at one point if their slopes differ.
In an equation of the form y=m*x+b, m is the slope and b the y-intercept.
Where you have two lines y=m1*x+b1, and y=m2*x+b2, you can solve
x=(b1-b2)/(m2-m1) and then subtitute to find y.

A) x=2*y+1  (y=0.5*x-0.5)
B) y=x-1
x = ((-0.5)-(-1))/(1 -0.5) = 0.5/0.5 = 1
y=0.5-0.5=0

In general curved lines are not required to intersect, and if they do
intersect there can be an infinite number of intersections. However, any
two curved lines with a known equations can be tested for intersections
in some interval.

#macro line_intersect_2d(m1 b1 m2 b2)
   #if (m1=m2)
      #error "There is no intersection!\n"
   #else
      #local result = <((b1-b2)/(m2-m1)),m1*((b1-b2)/(m2-m1))+b1>;
   #end
   result
#end

#declare I = line_intersect_2d(0.5, -0.5, 1, -1);


Post a reply to this message

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