# Probably a stupid question...

This topic is 2029 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi! See, I have a regular grid of points for a heightmap, and I want to modify the heights of the points in a radius around an arbitrary point in the grid (sort of like a radial gradient). I cant figure out how to do that without hardcoding each point offset in my code.

Could someone help me with this? I know it should be doable in a few loops but I can't wrap my head around how to do it...

##### Share on other sites
I would imagine that each point.z is a function of the radius. As the distance from the mouse cursor increases, height decreases.

##### Share on other sites

Go over the points in your grid, calculate distance from center point of circle to that point.  If it's less than the radius of the circle, then do point.z+=(1-distance_away/radius)*height_change to get a gradient

##### Share on other sites

Thanks for the answers. It is necessary to go all over the grid for calculating each single gradient? Since its a heightmap I'd have grids of 512x512 to 4k x 4k, maybe 8k x 8k. I have to calculate a few hundred small gradients (10 to 20 point radius). Seems wasteful.

Hm... You give me an idea... I can define a bounding box from the radius, loop over the points inside those bounds instead of the whole grid, and then calculate the gradient the way you described.

##### Share on other sites

Thanks for the answers. It is necessary to go all over the grid for calculating each single gradient? Since its a heightmap I'd have grids of 512x512 to 4k x 4k, maybe 8k x 8k. I have to calculate a few hundred small gradients (10 to 20 point radius). Seems wasteful.

Hm... You give me an idea... I can define a bounding box from the radius, loop over the points inside those bounds instead of the whole grid, and then calculate the gradient the way you described.

Yes that is precisely what I would do.

##### Share on other sites

Sweet! Not only worked but its also way shorter than my previous half finished method (90 lines against 30 ).

The gradients end in massive black holes since there are still a few things I need to fix, but it looks good. Thanks again!

1. 1
2. 2
Rutin
20
3. 3
A4L
15
4. 4
5. 5
khawk
14

• 13
• 26
• 10
• 11
• 9
• ### Forum Statistics

• Total Topics
633738
• Total Posts
3013617
×