POV-Ray : Newsgroups : povray.general : Function for air density Server Time
26 Nov 2024 22:46:27 EST (-0500)
  Function for air density (Message 1 to 8 of 8)  
From: SharkD
Subject: Function for air density
Date: 31 Aug 2009 08:56:31
Message: <4a9bc87f@news.povray.org>
I'm trying to write a function to calculate air density based on the 
following article:

http://en.wikipedia.org/wiki/Barometric_formula#Density_equations

My question is, is the "exp" function in the article the same as the 
"exp" function in POV-Ray? If not, what's the best way of going about 
writing these functions in SDL? My calculus is very rusty, but the 
description given here seems simple enough to implement:

http://en.wikipedia.org/wiki/Exponential_function#Continued_fractions_for_ex

-Mike


Post a reply to this message

From: scott
Subject: Re: Function for air density
Date: 31 Aug 2009 11:11:19
Message: <4a9be817$1@news.povray.org>
> I'm trying to write a function to calculate air density based on the 
> following article:
> 
> http://en.wikipedia.org/wiki/Barometric_formula#Density_equations
> 
> My question is, is the "exp" function in the article the same as the 
> "exp" function in POV-Ray? 

Yes.


Post a reply to this message

From: SharkD
Subject: Re: Function for air density
Date: 31 Aug 2009 17:09:36
Message: <4a9c3c10$1@news.povray.org>
scott wrote:
> Yes.

Thanks! The functions use multi-valued constants that will be tricky to 
implement. Also, there are no functions for values beyond 71km. Is that 
because the air so so thin that it's not worth calculating?

-Mike


Post a reply to this message

From: triple r
Subject: Re: Function for air density
Date: 31 Aug 2009 23:45:00
Message: <web.4a9c98231540ef51805d39df0@news.povray.org>
SharkD <mik### [at] gmailcom> wrote:
> Thanks! The functions use multi-valued constants that will be tricky to
> implement. Also, there are no functions for values beyond 71km. Is that
> because the air so so thin that it's not worth calculating?

The atmosphere is made up of different layers, each with their own typical
temperature gradient.  Just because the last reference point is at 71km, that
doesn't mean the formulae are not valid beyond that point.  It just means that
most of the interesting features are below.

If you just want a good approximation,

exp(-1.4237e-4 * h)

is a good approximation on a log scale, where h is in meters.  That tends to
overpredict where the density is large, so

exp(-1.2e-4 * h)

is a much better approximation for low altitudes.  Of course it overpredicts
high altitudes where the densities are tiny anyway.  These are just based on
least squares and eyeballing, respectively.  Which one to choose just depends
what you need it for.  If you're looking to model it with media or something,
I'd just split the difference.  It'd be in the ballpark anyway.  If you really
need it to be accurate, then work on implementing the formula on Wikipedia.

 - Ricky


Post a reply to this message

From: SharkD
Subject: Re: Function for air density
Date: 1 Sep 2009 18:41:16
Message: <4a9da30c$1@news.povray.org>
triple_r wrote:
> If you just want a good approximation,
> 
> exp(-1.4237e-4 * h)
> 
> is a good approximation on a log scale, where h is in meters.  That tends to
> overpredict where the density is large, so
> 
> exp(-1.2e-4 * h)
> 
> is a much better approximation for low altitudes.  Of course it overpredicts
> high altitudes where the densities are tiny anyway.  These are just based on
> least squares and eyeballing, respectively.  Which one to choose just depends
> what you need it for.  If you're looking to model it with media or something,
> I'd just split the difference.  It'd be in the ballpark anyway.  If you really
> need it to be accurate, then work on implementing the formula on Wikipedia.
> 
>  - Ricky


I'm applying the media to the difference of two very large spheres. 
Currently, the inner sphere (the Earth's radius) is set to "6375000 * 
Meters", where Meters is equal to 4. I'm not sure how big to make the 
outer sphere.

Could you please rewrite your density function to take this into 
account? I've created a few patterns that begin and end at X distances 
away from the center. I managed to get them to work if they are linear, 
but act strange when the functions are non-linear.

-Mike


Post a reply to this message

From: triple r
Subject: Re: Function for air density
Date: 1 Sep 2009 21:25:01
Message: <web.4a9dc7ea1540ef51958421d50@news.povray.org>
SharkD <mik### [at] gmailcom> wrote:
> I'm applying the media to the difference of two very large spheres.
> Currently, the inner sphere (the Earth's radius) is set to "6375000 *
> Meters", where Meters is equal to 4. I'm not sure how big to make the
> outer sphere.

Just make it go up to 50 or 100km.  The density at 100km is about 6e-4 percent
the density at the surface.  You'd have to try *very* hard to make this appear
as a discontinuity.

> Could you please rewrite your density function to take this into
> account?

exp(-1.2e-4*(h/Meters-6375000))

Does that sound right?  Just be aware of precision issues if you're going to
model the earth in meters.

 - Ricky


Post a reply to this message

From: SharkD
Subject: Re: Function for air density
Date: 2 Sep 2009 09:26:03
Message: <4a9e726b$1@news.povray.org>
triple_r wrote:
> Just make it go up to 50 or 100km.  The density at 100km is about 6e-4 percent
> the density at the surface.  You'd have to try *very* hard to make this appear
> as a discontinuity.
> 
>> Could you please rewrite your density function to take this into
>> account?
> 
> exp(-1.2e-4*(h/Meters-6375000))
> 
> Does that sound right?  Just be aware of precision issues if you're going to
> model the earth in meters.
> 
>  - Ricky

Here's my first attempt. I can't see a whole lot in the image. Could you 
suggest some better settings for the scattering media?

-Mike

//BEGIN
#local Meters = 4;
#local InnerRadius = EarthRadius;
#local OuterRadius = EarthRadius + 100000 * Meters;
#local BoundRadius = sin(acos(EarthRadius/OuterRadius)) * OuterRadius;
#local DiffrRadius = OuterRadius - InnerRadius;
#local ScaleAmount = 32;			// arbitrary number
#local HazePigment = pigment
{
	function {exp(-1.2e-4 * (f_r(x,y,z) - EarthRadius)/Meters)}
	color_map
	{
		[0 rgb 0]
		[1 rgb 1]
	}
}

difference
{
	sphere {0, OuterRadius}
	sphere {0, InnerRadius}
	bounded_by {cylinder {<0,EarthRadius,0,>, <0,OuterRadius,0,>, BoundRadius}}
	hollow
	material
	{
		texture {pigment {rgbt 1}}
		interior
		{
			media
			{
				scattering	{1, 0.5 * 1/ScaleAmount/1000}
				method		3
				intervals	1
//				samples		30, 100
				samples		10, 40
				density
				{
					pigment_pattern {HazePigment}
					density_map {[1/4 rgb 0][3/4 rgb 1]}
				}

			}
		}
		scale ScaleAmount
	}
	translate -y * EarthRadius
}
//END


Post a reply to this message

From: SharkD
Subject: Re: Function for air density
Date: 2 Sep 2009 10:21:19
Message: <4a9e7f5f@news.povray.org>
SharkD wrote:
> Here's my first attempt. I can't see a whole lot in the image. Could you 
> suggest some better settings for the scattering media?
> 
> -Mike

Nevermind. I am going to crap this and follow the TerraPOV tutorial instead.

-Mike


Post a reply to this message

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