POV-Ray : Newsgroups : povray.general : Using a function in a height_field declaration : Re: Using a function in a height_field declaration Server Time 2 Mar 2024 01:42:35 EST (-0500)
 Re: Using a function in a height_field declaration
 From: William F Pokorny Date: 14 Feb 2023 05:25:57 Message: <63eb61b5\$1@news.povray.org>
```
{
"@context": "https://schema.org",
"@type": "DiscussionForumPosting",
"@id": "#63eb61b5%241%40news.povray.org",
"headline": "Re: Using a function in a height_field declaration",
"dateCreated": "2023-02-14T10:25:57+00:00",
"datePublished": "2023-02-14T10:25:57+00:00",
"author": {
"@type": "Person",
"name": "William F Pokorny"
}
}
On 2/13/23 19:45, Cousin Ricky wrote:
> #declare MyFunction = function (x, y)
> { (2 - cos (x * 2*pi) - cos (y * 2*pi)) / 4
> }
>
> height_field
> { function 20, 20 { MyFunction (x, y) }
>    smooth

Good example. I always get tripped up when I come back to height_fields
because the function variables used are x and y (to match image based
height_fields I guess) while the generated height field sits atop the
x,z plane with y being the height. I too often first code my function
using x and z!

Bill P.

---
Another quick example.

#declare Fn02 = function { pattern { granite scale 0.5 } }
#declare Orange = srgb <1,0.50196,0>;
#declare HF00 = height_field {
function 800, 800 { Fn02(x,y,z) }
smooth
pigment { color Orange }
translate <-0.5,0,-0.5>
scale <2,0.05,2>
}
```