0

The code is from here. The author mentions that the two random values balance and max-offset are, 'one for whether midpoints are more likely to be offset inward or outward, and another for how far midpoints can be offset'.

I tried averaging parent vertices balanceand max-offset, tried different methods for balance (float, int, bool), and different ways of balance influencing max-offset, but the results are either too homogeneous or coils too much, and have no relationship with the demo (maps generated prior to this step are matching though).

I simply want to know how the variables balanceand max-offsetare factored in to calculate the midpoint displacement.

(defn offset-midpoint-rough
  [{[x1 y1] :position b1 :balance mo1 :max-offset}
   {[x2 y2] :position b2 :balance mo2 :max-offset}]
  (let [mx (/ (+ x1 x2) 2)
        my (/ (+ y1 y2) 2)
        vx (- (- y1 y2))
        vy (- x1 x2)
        balance (/ (+ b1 b2) 2)
        max-offset (/ (+ mo1 mo2) 2)
        d (* max-offset (- (rand) balance))]
    {:position [(+ mx (* d vx))
                (+ my (* d vy))]
     :balance balance
     :max-offset max-offset}))

BTW, I have the rest figured out without referring to the code posted, based on the textual description, and I'm coding in c# (Unity3D).

EDIT: Image showing comparison with previous code (blue highlight is new code which confounds me). Difference

Vignesh
  • 167
  • 2
  • 12
  • Read webpage : To do that, we’ll need to add some metadata to each point. Let’s wrap each of our irregular n-gon’s vertices in a map, including in it two random values: one for whether midpoints are more likely to be offset inward or outward, and another for how far midpoints can be offset. – jdweng Jun 10 '17 at 14:10
  • Yes, I have already done that (I have two random variables for each node) - but it is not clear from the post 'what' is the exact math. They appear to be float values. Averaging, using max value, addition, subtraction and multiplication between the parent values do not provide the results shown in the demo map. Also, it is not clear if the meta data for the child will be random or will be based on parents. This language looks alien to me! – Vignesh Jun 10 '17 at 14:21
  • Look at the code in the black boxes on the webpage. It is pretty clear. The code has comments like 1%, 2%, dist 1%, dist 2%, Balance is just a random number 0 - +1 (I think 1%) and max-offset is a standard deviation of .05 (.05%). I looks like it is based on the distance from the mid-point of the island. – jdweng Jun 10 '17 at 14:55
  • 1
    Your difficulties seem to pivot on [associative destructuring](https://clojure.org/guides/destructuring#_associative_destructuring), which the linked article explains well. – Thumbnail Jun 11 '17 at 01:00
  • @jdweng The %1 and % 2 are the parameters passed to the methods. But your standard deviation part got me thinking! – Vignesh Jun 11 '17 at 02:44
  • @Thumbnail Thanks for the link! I think I can understand it more or less now. `offset-midpoint-rough (Vector2 position1, Vector2 position2, float b1, float b2, float mo1, float mo2) { float mx = position1.x + position2.x / 2; float my = position1.y + position2.y / 2; float vx = position1.y - position.y; //-?? float vy = position1.x - position.x; float balance = bi + b2 / 2; float max-offset = mo1 + mo2 / 2; float d = max-offset * (Random.value - balance); Vector2 position = new Vector2(mx + (d * vx), my + (d * vy)); return (position, balance, max-offset) }` – Vignesh Jun 11 '17 at 03:05

0 Answers0