Hello,

I'm trying to implement a way to, given a region (a list of corners,
corners being a pair of edge numbers), find all regions which are
incident to it. I don't know how much I need to define for my problem
to be solved. I'll just give the code here and I can explain more if
needed. My idea is to find all of the regions which contain corners
opposite (across a crossing) to corners in the given region, and to
take the union.

pd1 =: 3 4 $ 1 5 2 4 3 1 4 6 5 3 6 2 NB. A planar diagram of a trefoil knot
getPairs =: {~ (,. 0&C.)@i...@#
corners =: getPairs"1 pd1

cyclicNext =: 1 : '([ ((4 | u&+)@{.@(#~ <&4)@] { {.@(#~ <&4)) i."2)~'
nextMatch =: {.@(((({:@[ = {...@])"1 # ]) ,/) -. 1 cyclicNext)
getRegion =: (nextMatch&) (@{.) ($:@,`...@.(-: {:)~`) (`: 6)
opposing =: 2 cyclicNext

corners is an n x 4 x 2 matrix where each 4 x 2 table is a clockwise
list of corners of a crossing. One can find the region in which a
corner is by doing the following:

region =: corners getRegion ,: 1 5

The result in this case is 3 x 2

3 1
5 3
1 5

For some reason

<@(pairs getRegion)@,:@(opposing&pairs"1) region

gives "stack error: opposing"

But

pairs getRegion"2 ,:@(opposing&pairs"1)region

works fine.

But strangely

<@(pairs getRegion)"2 ,:@(opposing&pairs"1)region

┌───────┬───────┬───────┐
│┌─────┐│┌─────┐│┌─────┐│
││┌───┐│││┌───┐│││┌───┐││
│││2 4│││││4 6│││││6 2│││
│││6 2│││││2 4│││││4 6│││
│││4 6│││││6 2│││││2 4│││
││└───┘│││└───┘│││└───┘││
│└─────┘│└─────┘│└─────┘│
└───────┴───────┴───────┘

At the moment I would just like a boxed list of the regions which
result from each corner. I have tried to figure out the problem for
ages now, and I'd be grateful for a hint.

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

Reply via email to