Abhishek Bhatia
Abhishek Bhatia

Reputation: 9796

Calculation of angle between turtle and patch

How do I calculate the above angle specified in the figure. The patch is known beforehand. enter image description here

Upvotes: 2

Views: 709

Answers (2)

Abhishek Bhatia
Abhishek Bhatia

Reputation: 9796

to-report calculate-turtles-in-cone2
  let px [pxcor] of patch-goal
  let py [pycor] of patch-goal
 ; show  [pxcor] of patch-goal
  set corner-1 list (px + 0.5 - .25)(py - 0.5)
  set corner-2 list (px - 0.5 + .25)(py - 0.5)
; show corner-1 
; show corner-2
  let head-1 towardsxy (item 0 corner-1) (item 1 corner-1)
  let head-2 towardsxy (item 0 corner-2) (item 1 corner-2)
  report abs (subtract-headings head-1 head-2)  
end

Upvotes: 1

Nicolas Payette
Nicolas Payette

Reputation: 14972

I won't write code for it, but here is a general recipe:

  • Find the four corner points of the patch by adding/subtracting 0.5 from pxcor and pycor;
  • Find the closest two corners by using distancexy;
  • Find the heading of each of those two points by using towardsxy;
  • Compute the difference between these two headings by using subtract-headings.

Upvotes: 6

Related Questions