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: [email protected]
[mailto:[email protected]] 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: [email protected]
[mailto:[email protected]] 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: [email protected]
[mailto:[email protected]] 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: [email protected]
[mailto:[email protected]] 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: [email protected]
[mailto:[email protected]] 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