POV-Ray : Newsgroups : povray.binaries.images : worley noise (not POV-Ray) : worley noise (not POV-Ray) Server Time
30 Mar 2025 23:30:44 EDT (-0400)
  worley noise (not POV-Ray)  
From: ingo
Date: 23 Mar 2025 11:20:00
Message: <web.67e026263742ca0917bac71e8ffb8ce3@news.povray.org>
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'
worley4d_cosine_standard_plane.png


 

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