1
$\begingroup$

I entered the following from @Rahul's answer in "Help with finding the point(s) inside a closed shape with the highest average ray length?" below my post. He told me I should enter his data one input at a time. The problem is I could not get a numerical number from my final input. Rahul believe there was problem with my computer. Here is the link to my calculations

In my first input tab I placed

curve = 
  DiscretizeRegion[
    ImplicitRegion[x^2 + y^2 + Sin[4 x] + Sin[4 y] == 4, {{x, -3, 3}, {y, -3, 3}}]]

Where I got a picture of the curve as in @Rahul's answer.

Then in my second input tab I placed

q = MeshCoordinates[curve];
edges = First /@ MeshCells[curve, 1];
signedAngle[a_, b_] := Arg[(Complex @@ a)/(Complex @@ b)]
avgRadius[p_] := 
  1/(2 π) Abs[
    Sum[
      Module[{q1, q2, r, dθ}, 
        q1 = q[[First @ e]]; 
        q2 = q[[Last @ e]]; 
        (* midpoint approximation *)
        r = EuclideanDistance[p, (q1 + q2)/2];
        dθ = signedAngle[q1 - p, q2 - p]; 
        r dθ], 
      {e, edges}]]

Finally in the third input tab I placed the following (but got the output in (**) to be).

avgRadius[{0, 0}]
(* avgRadius[{0,0}] *)

In my original post, I asked if someone could reply but it has been days and no one has said anything. Is there a possible way of getting a numerical output from my calculations? Is there something wrong with my computer?

$\endgroup$
3
  • $\begingroup$ The indentation of the lines following q = ... implies that some of your definitions are running together. Terminate each definition with ; to insure that there is no parsing mistake. avgRadius[{0, 0}] then returns 1.99725. $\endgroup$
    – Bob Hanlon
    Jan 5, 2016 at 22:49
  • $\begingroup$ @BobHanlon Could you show where exactly to place the semicolons I have tried doing this and still could not get any results. $\endgroup$
    – Arbuja
    Jan 6, 2016 at 2:37
  • $\begingroup$ There will be no trouble if you start with a fresh kernel and evaluate eachSet andSetDelayed in a separate cell. $\endgroup$
    – m_goldberg
    Jan 6, 2016 at 6:06

1 Answer 1

2
$\begingroup$
curve = DiscretizeRegion[
  ImplicitRegion[
   x^2 + y^2 + Sin[4 x] + Sin[4 y] == 4, {{x, -3, 3}, {y, -3, 3}}]]

enter image description here

q = MeshCoordinates[curve];

edges = First /@ MeshCells[curve, 1];

signedAngle[a_, b_] := Arg[(Complex @@ a)/(Complex @@ b)];

avgRadius[p_] := 1/(2 π) Abs[
    Sum[
     Module[{q1, q2, r, dθ},
      q1 = q[[First@e]];
      q2 = q[[Last@e]];
      r = EuclideanDistance[p, (q1 + q2)/2]; (* midpoint approximation *)
      dθ = signedAngle[q1 - p, q2 - p];
      r dθ],
     {e, edges}]];

avgRadius[{0, 0}]

(*  1.99725  *)
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.