Can you help me show only the correct solution for this code.  It is the one
image that is preceded by a 1.  Any simplifications would be fun too.

load 'plot'
pd 'reset'
P=:1+?(2,8)$6
Q=:0 1{"1 P
MID=:-:+/"1  Q
MP=:-%/-/"1 Q
X1=:0
Y1=:(MP*( X1- 0{MID)) + 1{MID
Y2=:7
X2=:(Y2+(MP*0{MID)-1{MID)%MP
X3=:7
Y3=:(MP*( X3- 0{MID)) + 1{MID
Y4=:0
X4=:(Y4+(MP*0{MID)-1{MID)%MP
V=:Y1,X2,Y3,X4
POS=:(2=+/"1#:i.16)##:i.16
R=:|:(0,0,0, X2,7,7, 7,X4),.0,Y1,7,7, 7 , Y3,0,0
S=:(*./"2 (0<:R)*.  R<:7)#"1 R
Y1=:(0>.Y1)
Y1=:(Y1<.7)
X2=:(0>.X2)
T1=:6($"1)3 5 4 {"1 S
T2=:6($"1)3 5 0 1 2 {"1 S
T3=:6($"1)5 2 3 4 {"1 S
T4=:6($"1)5 2 1 0 {"1 S
T5=:6($"1)2 4 3 {"1 S
T6=:6($"1)2 4 5 0 1 {"1 S
T7=:6($"1)1 5 0 {"1 S
T8=:6($"1)1 5 4 3 2 {"1 S
T9=:6($"1)1 4 3 2{"1 S
T10=:6($"1)1 4 5 0 {"1 S
T11=:6($"1)3 1 2 {"1 S
T12=:6($"1)3 1 0 5 4 {"1 S
dat=:(<"2)>2 2$0 2 1 3 { T1,T2 
'aspect 1'plot dat
P
V
]*./ 1 0 0 0 0 0=*./"1((0<:V)*.V<:7)="1 POS
pd 'type poly'
pd 'itemcolor blue, yellow, green, red'
pd dat
pd 'type marker'
pd 'markersize 1.2'
pd 'itemcolor black'
pd (<"1) 0 1 2{"1 P
pd 'show'
]*./ 0 1 0 0 0 0=*./"1((0<:V)*.V<:7)="1 POS
dat=:(<"2)>2 2$0 2 1 3 { T3,T4 
pd 'type poly'
pd 'itemcolor blue, yellow, green, red'
pd dat
pd 'type marker'
pd 'markersize 1.2'
pd 'itemcolor black'
pd (<"1) 0 1 2{"1 P
pd 'show'
]*./ 0 0 1 0 0 0=*./"1((0<:V)*.V<:7)="1 POS
dat=:(<"2)>2 2$0 2 1 3 { T5,T6 
pd 'type poly'
pd 'itemcolor blue, yellow, green, red'
pd dat
pd 'type marker'
pd 'markersize 1.2'
pd 'itemcolor black'
pd (<"1) 0 1 2{"1 P
pd 'show'
]*./ 0 0 0 1 0 0=*./"1((0<:V)*.V<:7)="1 POS
dat=:(<"2)>2 2$0 2 1 3 { T7,T8 
pd 'type poly'
pd 'itemcolor blue, yellow, green, red'
pd dat
pd 'type marker'
pd 'markersize 1.2'
pd 'itemcolor black'
pd (<"1) 0 1 2{"1 P
pd 'show'
]*./ 0 0 0 0 1 0=*./"1((0<:V)*.V<:7)="1 POS
]dat=:(<"2)>2 2$0 2 1 3 { T9,T10 
pd 'type poly'
pd 'itemcolor blue, yellow, green, red'
pd dat
pd 'type marker'
pd 'markersize 1.2'
pd 'itemcolor black'
pd (<"1) 0 1 2{"1 P
pd 'show'
]*./ 0 0 0 0 0 1=*./"1((0<:V)*.V<:7)="1 POS
dat=:(<"2)>2 2$0 2 1 3 { T11,T12 
pd 'type poly'
pd 'itemcolor blue, yellow, green, red'
pd dat
pd 'type marker'
pd 'markersize 1.2'
pd 'itemcolor black'
pd (<"1) 0 1 2{"1 P
pd 'show'

Linda


-----Original Message-----
From: programming-boun...@jsoftware.com
[mailto:programming-boun...@jsoftware.com] On Behalf Of Linda Alvord
Sent: Friday, July 13, 2012 3:29 AM
To: 'Programming forum'
Subject: Re: [Jprogramming] Challenge 13 Plot Alot

A small step forward:

If you run these lines the 7 unit square is displayed. The final 4 element
result will have two values that are in the range from 0 to 7. They
represent the intersections of the perpendicular bisector of the first two
random points in P and the sides of the square. The list is in order around
the square from left, top, right and bottom.

load 'plot'
pd 'reset'
P=:?(2,8)$8
Q=:0 1{"1 P
MID=:-:+/"1  Q
MP=:-%/-/"1 Q
X1=:0
Y1=:(MP*( X1- 0{MID)) + 1{MID
X2=:7
Y2=:(MP*( X2- 0{MID)) + 1{MID
E=:0 7
F=:Y1,Y2
A=:(B=:0 0 7 7 0);C=:0 7 7 0 0
D=:E;F
'aspect 1'plot G=:(B,E);C,F
Y3=:0
X3=:(Y3+(MP*0{MID)-1{MID)%MP
Y4=:7
X4=:(Y4+(MP*0{MID)-1{MID)%MP
Y1,X4,Y2,X3
_0.125 5.7 8.625 0.1
   
Improvements welcome! Now the problem is to paint the two polygons in the
square two different colors.

 Linda

-----Original Message-----
From: programming-boun...@jsoftware.com
[mailto:programming-boun...@jsoftware.com] On Behalf Of Linda Alvord
Sent: Monday, July 09, 2012 10:47 PM
To: 'Programming forum'
Subject: Re: [Jprogramming] Challenge 13 Plot Alot

Here's a start on making a plot.

load 'plot'
   NB.pd 'reset'
   P=:?(2,8)$8
   Q=:0 1{"1 P
   MID=:-:+/"1  Q
   MP=:-%/-/"1 Q
   XQ\=:0
   Y1=:(MP*( X- 0{MID)) + 1{MID
   X=:7
   Y2=:(MP*( X- 0{MID)) + 1{MID
   E=:0 7
   F=:Y1,Y2
   A=:(B=:0 0 7 7 0);C=:0 7 7 0 0
   D=:E;F
   'aspect 1'plot G=:(B,E);C,F
   P
6 5 1 3 4 0 6 6
4 7 3 6 1 2 4 3
   Q
6 5
4 7
   
To see the code in action you must put it in a script and run it.  The plot
will be an 8x8 square. (vertical lines are not excluded yet) The first two
random points to be considered are in  Q .  The perpendicular bisector of
the two random points crosses square.  How can I paint the two polygons in
the square in two different colors?

Thanks in advance.

Linda
-----Original Message-----
From: programming-boun...@jsoftware.com
[mailto:programming-boun...@jsoftware.com] On Behalf Of Linda Alvord
Sent: Saturday, July 07, 2012 4:14 AM
To: 'Programming forum'
Subject: Re: [Jprogramming] Challenge 13 Plot Alot

Somehow I didn't  include the 8 points.  Here they are.

load 'plot'
pd 'reset' 
'aspect 1'plot (_1 8);_1 8
pd 'itemcolor red'
pd 'type marker'
pd 'markersize 1.2'
pd 'itemcolor red'
pd P =:(?8$8);?8$8
pd 'show'

-----Original Message-----
From: programming-boun...@jsoftware.com
[mailto:programming-boun...@jsoftware.com] On Behalf Of Linda Alvord
Sent: Friday, July 06, 2012 5:27 PM
To: 'Programming forum'
Subject: Re: [Jprogramming] Challenge 13 Plot Alot

Here's a simple plot of eight random points.  I don't know how to change the
aspect without having another graph generated.

load 'plot'
pd 'reset' 
'aspect 1'plot (_1 8);_1 8
pd 'itemcolor red'
pd 'type marker'
pd 'markersize 1.2'
pd 'itemcolor red'
pd P
pd 'show'


Any thoughts?

Linda

-----Original Message-----
From: programming-boun...@jsoftware.com
[mailto:programming-boun...@jsoftware.com] On Behalf Of Linda Alvord
Sent: Tuesday, July 03, 2012 10:57 AM
To: 'Programming forum'
Subject: Re: [Jprogramming] Challenge 13 Plot Alot

Hi, I checked my copy of my e-mail and this script was attached.  Here it is
again.  Maybe you don't get attachments.  Also here is a copy of the script.

p=: 13 :'?(x,2)$y'
N=:26
P=:N p N
lat=: 13 :'(y,+:y)$''. '''
lat 5
dots=: 13 :'<"1 (0{"1 y),.2*1{"1 y'
dots 4 p 8
spots=: 13 :'((i.x){(65+i.26){a.)(dots x p y)}lat y' 
5 spots 11
12 spots 4
N spots N

load 'viewmat'
NB. (number of points) voronoi (shape)
NB. Generates an array of indices of the nearest point
b=: 13 :'(i.y),."0 1 i.y'
p=: 13 :'?(y,2)$ y'
m=: 13 :'(i.<./)"1 +/"1 *:x-"1/~y'

NB. Palettes of colors used in the examples below viewmat {"2 m b 2

viewmat {"2 m b 3

viewmat {"2 m b 4

viewmat {"2 m b 5

viewmat {"2 m b 6

viewmat {"2 m b 7

viewmat {"2 m b 8

viewmat {"2 m b 9

NB. Regions
viewmat (p 2) m b 2

viewmat (p 3) m b 3

viewmat (p 4) m b 4

viewmat (p 5) m b 5

viewmat (p 6) m b 6

viewmat (p 7) m b 7

viewmat (p 8) m b 8

viewmat Q=:(P=:p 9) m b 9
P
Q


Linda

-----Original Message-----
From: programming-boun...@jsoftware.com
[mailto:programming-boun...@jsoftware.com] On Behalf Of Mike Day
Sent: Tuesday, July 03, 2012 8:38 AM
To: Programming forum
Subject: Re: [Jprogramming] Challenge 13 Plot Alot

Attachment, Linda?

Mike

On 03/07/2012 2:41 AM, Linda Alvord wrote:
> A new strategy for this challenge:  As you make any progress on this 
> challenge, please send it along right away.  Working together  we may 
> make any solution become better and better.
>
>   
>
> I've been trying to understand some code for Voronoi regions. The 
> script is attached develops the code.  What I really want to do is 
> make a similar progression of plots in conventional X and Y 
> coordinates with polygon regions separated by line segments. Dots in 
> each regions should show the random points that determine the regions.
>
>   
>
> When you try my code in  jhs  and  gtk  you will find the results very 
> different in style.  I think the  8 plots will probably be more 
> similar in the two different environments.
>
>   
>
> There are many examples  of this problem available on the web, but 
> what I'm interested in is getting a sequence of steps that will help a 
> reader to understand how those results have been achieved.
>
>   
>
> Feel free to ask questions along the way.  I will be working on the 
> same problem along with you.
>
>
>
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm


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

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

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

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

----------------------------------------------------------------------
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