]pts =. _2 ]\ 1 1   2 2   3 4   NB. points as (x,y)
1 1
2 2
3 4

   ]zpts =. j./ |: pts  NB. points in complex plane
1j1 2j2 3j4

   zorigin =. 0j0
   NB. verb to rotate points y counterclockwise by angle x
   rot =. {{ zorigin + (y-zorigin) * ^ j. x }}"0 _

   NB. Get the angles to use.  Each pairwise point difference is a vector.  Calculate them, run    NB. into a list, discard 0s, find the angle.  Negate the angle so as to rotate CW (which puts y    NB. values the same, and append a copy with pi/2 added (which rotation puts x values the same).
   NB. Force to quadrants I and II, discard duplicates, sort.
   ]angles =. /:~ ~. 1p1 | (, 0.5p1&+) - 12 o. 0 -.~ , -/~ zpts
0.463648 0.588003 0.785398 2.03444 2.1588 2.35619

   NB. Rotate by each angle to see that coordinates match
   angles rot zpts
    0.447214j1.34164     0.894427j2.68328   0.894427j4.91935
     0.27735j1.38675        0.5547j2.7735     0.27735j4.9923
           0j1.41421            0j2.82843  _0.707107j4.94975
   _1.34164j0.447214    _2.68328j0.894427  _4.91935j0.894427
    _1.38675j0.27735       _2.7735j0.5547    _4.9923j0.27735
_1.41421j1.11022e_16 _2.82843j2.22045e_16 _4.94975j_0.707107

Henry Rich



On 11/16/2023 9:44 AM, 'PMA' via Programming wrote:
Dear J-Programming Forum,

I want to make a script that, given the X/Y values of a 2D dot-graph, will rotate the graph around its designated origin, looking for instances of 2 or more points coming into new horizontal &/or vertical alignment, and at each such instance output the full set of current X/Y values (integer-rounded).

Could you point me to the main needed ingredients?

Thanks in advance,

Peter Armstrong
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to