Euclidean Distance Formula Help

Started by WAS, March 09, 2022, 01:21:04 PM

Previous topic - Next topic

WAS

I made a euclidean distance formula to use with my functions to create populators for Terragen generators. When I asked for help online with my spheroid location generator someone told me my euclidean distance wasn't accurate and would create errors. I asked him what he meant, but he hasn't responded now years later. I am questioning if there is actually anything wrong with it? I tried some changes within my limited scope of math, and actually just managed to break it every time.

Is there anyone with some coding and trig knowledge that could look at this? Is this wrong? Maybe @Matt ? I know you offered some invaluable help before. Thanks so much. I am trying to make a new populator which is spheroid, but also can limit on Y and just came back to this issue.


Info: L1, and L2 are the location arrays in X, Y, Z. So L1 would be X, and so on.

The forums are messing up the code. Here it is online: https://onecompiler.com/php/3xvmkq3mc






WAS

Additionally, anyone knows what precision scale Terragen has for integers? (how many points in the decimal place it accepts)? Since this is a 3D app and precision is pretty important to location, wondering if my program is truncating too many decibel places. Floats usually only come out with 4 digits in decibel place.

cyphyr

Unfortunately I don't even know what euclidean means in this instance.
However I do know that Terragen's accuracy diminishes the further one gets from the origin.
www.richardfraservfx.com
https://www.facebook.com/RichardFraserVFX/
/|\

Ryzen 9 5950X OC@4Ghz, 64Gb (TG4 benchmark 4:13)

WAS

#3
Quote from: cyphyr on March 09, 2022, 03:20:26 PMUnfortunately I don't even know what euclidean means in this instance.
However I do know that Terragen's accuracy diminishes the further one gets from the origin.

Yeah it does. I think this more impacts objects the most as they are defined, and have no adaption. So if the coordinates to each piece of the objects are super far from origin, all the mathing for their locations will lose precision. Which then, as we have seen, objects start breaking apart and doing weird things.

Euclidean distance is the distance (in a straight line basically) between two locations in 3D space, or Euclidean space in this instance: https://en.wikipedia.org/wiki/Euclidean_distance

I am noticing issues with my system now, for example, if my radius for a spheroid populator is greater than 1e+06, the whole server will just throw a 500 error. PHP can't even give me an error on what exactly is wrong. Just whole server crashes for that request. Looking into using BCMath PHP extension, which works better for large numbers, and I can also define the scale of the numbers (decimal points). So I can match the exact scale TG is limited too.Which means all my mathing can be interpreted by TG as is without it rounding or my code rounding (which is more the latter right now).

Some more random info: The euclidean distance here, because it's a straight line from the point of origin defined by the user, we can easily check if a location is outside the radius they define to create a sphere of populations. Handy for craters on a planet, or stars, or fireflies, or whatever where you don't want a noticeable square to their shape with my cubeoid generator, which just simply checks if locations are greater than the define XYZ dimensions.

Matt

I think your math is correct. I wonder if the feedback you got was about how it was being used, rather than the distance function itself, but I don't know.
Just because milk is white doesn't mean that clouds are made of milk.

WAS

I think you are right. I am I am just coming back to it without remembering. I am in fact pretty sure you corrected me on its usage, and how I didn't even need it. Only reason I thought of using it again is I was going to divide it by a "percentage" and see if points are beyond whatever limit on Y. Which is unnecessary as I can just check if Y is above/below the limit and if it is, make it's Y the limit, or just go for recursion and try again but that added serious load to the script so I opted out of that. It literally resulted in full apache crash in 3/4 the scenarios. Lol way to many resources.