POV-Ray : Newsgroups : povray.general : Need math help Server Time
10 Aug 2024 07:22:39 EDT (-0400)
  Need math help (Message 7 to 16 of 16)  
<<< Previous 6 Messages Goto Initial 10 Messages
From: Sebastian Strand
Subject: SV: Need math help
Date: 10 Mar 2000 06:17:48
Message: <38c8d9dc@news.povray.org>
> Poor little me, trying to carve out a name for myself in the wonderous
field
> of macros, and everyone has to go and use VanSickle's...
> Well I see yours is nice and lengthy compared to mine ;-)

Well, thanks to all three of you that presented a solution. I will now
proceed to try and decide which one to use, probably by testing which macro
parses quickest  :)








Post a reply to this message

From: Sebastian Strand
Subject: SV: Need math help
Date: 10 Mar 2000 08:56:08
Message: <38c8fef8@news.povray.org>
"David Fontaine" <dav### [at] faricynet> wrote:
> If you want the math behind it I can give it to you :-)
> And if you want a second cone differenced out of it to smoothly connect
the
> interior as well, most of the work is already done.

I tried your macro, but it seems that the radius of the cone is slightly
smaller than it should be. There is a tiny visible edge at the connection
point when using highlights, and that same edge does not occur with
VanSickle's version.








Post a reply to this message

From: Tor Olav Kristensen
Subject: Re: SV: Need math help
Date: 10 Mar 2000 13:05:47
Message: <38C93865.F5FE5F14@hotmail.com>
Hi

Sebastian Strand wrote:

> Well, thanks to all three of you that presented a solution. I will now
> proceed to try and decide which one to use, probably by testing which macro
> parses quickest  :)

Try this:

#macro TorusConnect(SP,SMaR,SMiR,EP,EMaR,EMiR)

  #local a=EP-SP;
  #local b=SMaR-EMaR;
  #local c=SMiR-EMiR;
  #local d=vdot(a,a);
  #local e=d+b*b;
  #local f=sqrt(d);
  #local g=sqrt(e-c*c);
  #local h=(f*g-c*b)/e;
  #local i=(f*c+g*b)/e;
  #local j=a/f;

  cone { SMiR*i*j+SP,SMiR*h+SMaR,(EMiR*i+f)*j+SP,EMiR*h+EMaR }

#end // macro TorusConnect

Tor Olav

mailto:tor### [at] hotmailcom
http://www.crosswinds.net/~tok/tokrays.html


Post a reply to this message

From: David Fontaine
Subject: Re: SV: Need math help
Date: 10 Mar 2000 18:23:20
Message: <38C98325.4BF2CDEC@faricy.net>
Sebastian Strand wrote:

> I tried your macro, but it seems that the radius of the cone is slightly
> smaller than it should be. There is a tiny visible edge at the connection
> point when using highlights, and that same edge does not occur with
> VanSickle's version.

$%&%$&#!!!!!

--
___     _______________________________________________
 | \     |_          <dav### [at] faricynet> <ICQ 55354965>
 |_/avid |ontaine        http://www.faricy.net/~davidf/

"The only difference between me and a madman is that I'm not mad." -Dali


Post a reply to this message

From: John VanSickle
Subject: Re: Need math help
Date: 10 Mar 2000 21:29:40
Message: <38C9B210.6698DB45@erols.com>
David Fontaine wrote:
> 
> Poor little me, trying to carve out a name for myself in the wonderous
> field of macros, and everyone has to go and use VanSickle's...
> Well I see yours is nice and lengthy compared to mine ;-)

I avoided using the trig functions.  I also made local copies of the
arguments, so that if the user passes an expression as one of the arguments,
that expression will be evaluated.  For instance, this macro

  #macro MyMacro(A,B) (A-B) #end

can be invoked this way:

  #local J=MyMacro(77*2,45*2-23*3);

which POV-Ray will evalaute as:

  #local J=77*2-45*2-23*3;

which is almost certainly *not* what the user wanted.

Regards,
John


Post a reply to this message

From: Tor Olav Kristensen
Subject: Re: Need math help
Date: 10 Mar 2000 21:54:11
Message: <38C9B435.53B140AB@hotmail.com>
Hi John

John VanSickle wrote:

> I avoided using the trig functions.  I also made local copies of the
> arguments, so that if the user passes an expression as one of the arguments,
> that expression will be evaluated.

Will this also make it parse faster?

What if one uses () around the passed arguments when one uses them
in i.e. multiplications and divisions?

And if so, would it be sufficient to do this in the cone statement in the last
torus-connect macro i posted?

Like this:
cone { (SMiR)*i*j+SP,(SMiR)*h+SMaR,((EMiR)*i+f)*j+SP,(EMiR)*h+EMaR }

() around SMiR and  EMiR ...

By the way: Did you recognize any of the math in that macro?

Regards

Tor Olav

mailto:tor### [at] hotmailcom
http://www.crosswinds.net/~tok/tokrays.html


Post a reply to this message

From: John VanSickle
Subject: Re: Need math help
Date: 10 Mar 2000 22:38:39
Message: <38C9C23B.6CF9476C@erols.com>
Tor Olav Kristensen wrote:
> 
> John VanSickle wrote:
> 
> > I avoided using the trig functions.  I also made local copies of the
> > arguments, so that if the user passes an expression as one of the arguments,
> > that expression will be evaluated.
> 
> Will this also make it parse faster?

That depends on how much faster a label look-up is compared to the evaluation
of an expression.  Most of the time a single variable or a constant is being
passed.

> What if one uses () around the passed arguments when one uses them
> in i.e. multiplications and divisions?

Same effect.

> And if so, would it be sufficient to do this in the cone statement in the last
> torus-connect macro i posted?
> 
> Like this:
> cone { (SMiR)*i*j+SP,(SMiR)*h+SMaR,((EMiR)*i+f)*j+SP,(EMiR)*h+EMaR }
> 
> () around SMiR and  EMiR ...

Yes, the parentheses force evaluation of the argument so that expressions
can be passed without causing an error.  This is important if you are going
to had it out for other people to use.

> By the way: Did you recognize any of the math in that macro?

It appears to be the same calculations as what I posted, although I may
have taken an unnecessary root here or there.  I used long labels as the
arguments in the sample code so that people could tell which argument to
the macro was supposed to be the start point, the end point, etc., without
having to puzzle out the acronyms.  In a real .INC file I use shorter
labels that follow the naming coventions I use in all of my scene code.

Regards,
John
-- 
ICQ: 46085459


Post a reply to this message

From: Chris Huff
Subject: Re: Need math help
Date: 11 Mar 2000 08:35:00
Message: <chrishuff_99-1443D5.08364911032000@news.povray.org>
In article <38C9B210.6698DB45@erols.com>, John VanSickle 
<van### [at] erolscom> wrote:

> ... I also made local copies of the arguments, so that if the user 
> passes an expression as one of the arguments, that expression will be 
> evaluated.  For instance, this macro
> 
>   #macro MyMacro(A,B) (A-B) #end
> 
> can be invoked this way:
> 
>   #local J=MyMacro(77*2,45*2-23*3);
> 
> which POV-Ray will evalaute as:
> 
>   #local J=77*2-45*2-23*3;
> 
> which is almost certainly *not* what the user wanted.

POV always evaluates the parameters, which is one of it's differences 
with C macros.
See this section in the manual: 4.2.8.3  Are POV-Ray Macros a Function 
or a Macro?

-- 
Chris Huff
e-mail: chr### [at] yahoocom
Web page: http://chrishuff.dhs.org/


Post a reply to this message

From: John VanSickle
Subject: Re: Need math help
Date: 11 Mar 2000 15:30:41
Message: <38CAAF70.7148E33C@erols.com>
Chris Huff wrote:
> 
> In article <38C9B210.6698DB45@erols.com>, John VanSickle
> <van### [at] erolscom> wrote:
> 
> > ... I also made local copies of the arguments, so that if the user
> > passes an expression as one of the arguments, that expression will be
> > evaluated.  For instance, this macro
> >
> >   #macro MyMacro(A,B) (A-B) #end
> >
> > can be invoked this way:
> >
> >   #local J=MyMacro(77*2,45*2-23*3);
> >
> > which POV-Ray will evalaute as:
> >
> >   #local J=77*2-45*2-23*3;
> >
> > which is almost certainly *not* what the user wanted.
> 
> POV always evaluates the parameters, which is one of it's differences
> with C macros.
> See this section in the manual: 4.2.8.3  Are POV-Ray Macros a Function
> or a Macro?

Hmm, the docs back you up on this.  I guess that I do it this way because
it fixed a bug I had somewhere...

-- 
ICQ: 46085459


Post a reply to this message

From: David Fontaine
Subject: Re: Need math help
Date: 11 Mar 2000 16:45:25
Message: <38CABD9D.5BB9663F@faricy.net>
John VanSickle wrote:

> I avoided using the trig functions.  I also made local copies of the
> arguments, so that if the user passes an expression as one of the arguments,
> that expression will be evaluated.  For instance, this macro
>
>   #macro MyMacro(A,B) (A-B) #end
>
> can be invoked this way:
>
>   #local J=MyMacro(77*2,45*2-23*3);
>
> which POV-Ray will evalaute as:
>
>   #local J=77*2-45*2-23*3;
>
> which is almost certainly *not* what the user wanted.

Bzz, wrong!
Run this code:

#macro Test(a,b) a-b #end
#render concat(str(Test(2*5,2*4-2*3),1,0),"\n")
sphere{0,1} //So POV doesn't whine

--
___     _______________________________________________
 | \     |_          <dav### [at] faricynet> <ICQ 55354965>
 |_/avid |ontaine        http://www.faricy.net/~davidf/

"The only difference between me and a madman is that I'm not mad." -Dali


Post a reply to this message

<<< Previous 6 Messages Goto Initial 10 Messages

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