A plane cut through 4D worleynoise, with a different distance method than
ususal. I used cosine_distance = 1.0 - cosineSimilarity(p, q)
https://en.wikipedia.org/wiki/Cosine_similarity
In each cell a feature vector is created based on the (random) feature point in
it.
for i in featurepoint.len:
sin(featurePoint[i] * 12.9898 + float(i) * 78.233 + float(worley.seed) *
4.1414) * 0.5 + 0.5
then while rendering another vector is created at the hit point:
for i in 0..<p.len:
pointVec[i] = sin(p[i] * 12.9898 + float(i) * 43.5453) * 0.5 + 0.5
now the cosine distances are calculated between the point and nearest
neighbours.
Done in Nim as I couldn't get it going in POV-Ray.
proc cosineSimilarity*(p, q: Point): float =
## Calculates the cosine similarity between two vectors.
if p.len != q.len:
raise newException(ValueError, "Vectors must have the same dimensions")
var dotProduct = 0.0
var normP = 0.0
var normQ = 0.0
for i in 0..<p.len:
dotProduct += p[i] * q[i]
normP += p[i] * p[i]
normQ += q[i] * q[i]
normP = sqrt(normP)
normQ = sqrt(normQ)
if normP == 0 or normQ == 0:
raise newException(ValueError, "Cannot calculate similarity for zero
vector")
result = dotProduct / (normP * normQ)
proc cosineDistance*(p, q: Point): float =
## Calculates the cosine distance between two vectors.
## D(p,q) = 1 - cos(θ)
result = 1.0 - cosineSimilarity(p, q)
ingo
Post a reply to this message
Attachments:
Download 'worley4d_cosine_standard_plane.png' (140 KB)
Preview of image 'worley4d_cosine_standard_plane.png'

|