/ *   
 
   *   P R O J E C T :   N y A R T o o l k i t 
 
   *   - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
 
   *   T h i s   w o r k   i s   b a s e d   o n   t h e   o r i g i n a l   A R T o o l K i t   d e v e l o p e d   b y 
 
   *       H i r o k a z u   K a t o 
 
   *       M a r k   B i l l i n g h u r s t 
 
   *       H I T L a b ,   U n i v e r s i t y   o f   W a s h i n g t o n ,   S e a t t l e 
 
   *   h t t p : / / w w w . h i t l . w a s h i n g t o n . e d u / a r t o o l k i t / 
 
   * 
 
   *   T h e   N y A R T o o l k i t   i s   J a v a   e d i t i o n   A R T o o l K i t   c l a s s   l i b r a r y . 
 
   *   C o p y r i g h t   ( C ) 2 0 0 8 - 2 0 0 9   R y o   I i z u k a 
 
   * 
 
   *   T h i s   p r o g r a m   i s   f r e e   s o f t w a r e :   y o u   c a n   r e d i s t r i b u t e   i t   a n d / o r   m o d i f y 
 
   *   i t   u n d e r   t h e   t e r m s   o f   t h e   G N U   G e n e r a l   P u b l i c   L i c e n s e   a s   p u b l i s h e d   b y 
 
   *   t h e   F r e e   S o f t w a r e   F o u n d a t i o n ,   e i t h e r   v e r s i o n   3   o f   t h e   L i c e n s e ,   o r 
 
   *   ( a t   y o u r   o p t i o n )   a n y   l a t e r   v e r s i o n . 
 
   *   
 
   *   T h i s   p r o g r a m   i s   d i s t r i b u t e d   i n   t h e   h o p e   t h a t   i t   w i l l   b e   u s e f u l , 
 
   *   b u t   W I T H O U T   A N Y   W A R R A N T Y ;   w i t h o u t   e v e n   t h e   i m p l i e d   w a r r a n t y   o f 
 
   *   M E R C H A N T A B I L I T Y   o r   F I T N E S S   F O R   A   P A R T I C U L A R   P U R P O S E .     S e e   t h e 
 
   *   G N U   G e n e r a l   P u b l i c   L i c e n s e   f o r   m o r e   d e t a i l s . 
 
   * 
 
   *   Y o u   s h o u l d   h a v e   r e c e i v e d   a   c o p y   o f   t h e   G N U   G e n e r a l   P u b l i c   L i c e n s e 
 
   *   a l o n g   w i t h   t h i s   p r o g r a m .     I f   n o t ,   s e e   < h t t p : / / w w w . g n u . o r g / l i c e n s e s / > . 
 
   *   
 
   *   F o r   f u r t h e r   i n f o r m a t i o n   p l e a s e   c o n t a c t . 
 
   * 	 h t t p : / / n y a t l a . j p / n y a t o o l k i t / 
 
   * 	 < a i r m a i l ( a t ) e b o n y . p l a l a . o r . j p >   o r   < n y a t l a ( a t ) n y a t l a . j p > 
 
   *   
 
   * / 
 
 n a m e s p a c e   j p . n y a t l a . n y a r t o o l k i t . c s . c o r e 
 
 { 
 
 
 
 
 
 
 
 
 
         / * * 
 
           *   S0n0000o00^jMR0v}_k0	YcW0~0Y00
 
           *   ^jMRn0#}Y00 }0;NbRRgk0K0Q0f00v}_k0W0~0Y00
 
           * / 
 
         p u b l i c   c l a s s   N y A R C o o r d 2 L i n e a r 
 
         { 
 
                 p r i v a t e   r e a d o n l y   d o u b l e [ ]   _ x p o s ; 
 
                 p r i v a t e   r e a d o n l y   d o u b l e [ ]   _ y p o s ; 
 
                 p r i v a t e   r e a d o n l y   I N y A R P c a 2 d   _ p c a ; 
 
                 p r i v a t e   r e a d o n l y   N y A R D o u b l e M a t r i x 2 2   _ _ g e t S q u a r e L i n e _ e v e c   =   n e w   N y A R D o u b l e M a t r i x 2 2 ( ) ; 
 
                 p r i v a t e   r e a d o n l y   d o u b l e [ ]   _ _ g e t S q u a r e L i n e _ m e a n   =   n e w   d o u b l e [ 2 ] ; 
 
                 p r i v a t e   r e a d o n l y   d o u b l e [ ]   _ _ g e t S q u a r e L i n e _ e v   =   n e w   d o u b l e [ 2 ] ; 
 
                 p r i v a t e   r e a d o n l y   N y A R O b s e r v 2 I d e a l M a p   _ d i s t _ f a c t o r ; 
 
                 / * * 
 
                   *   0000000g0Y00
 
                   *   *S_CQ;uPn0jk0wck000000h00000c[W0f000000000ubW0~0Y00
 
                   *   @ p a r a m   i _ s i z e 
 
                   *   eQR;uPn0000
 
                   *   @ p a r a m   i _ d i s t f a c t o r 
 
                   *   =jWjk00܈ckY004XTk000000000c[W0~0Y00
 
                   *   n u l l n04XT0܈ck0LD0~0[000
 
                   * / 
 
                 p u b l i c   N y A R C o o r d 2 L i n e a r ( N y A R I n t S i z e   i _ s i z e ,   I N y A R C a m e r a D i s t o r t i o n F a c t o r   i _ d i s t f a c t o r ) 
 
                 { 
 
                         i f   ( i _ d i s t f a c t o r   ! =   n u l l ) 
 
                         { 
 
                                 t h i s . _ d i s t _ f a c t o r   =   n e w   N y A R O b s e r v 2 I d e a l M a p ( i _ d i s t f a c t o r ,   i _ s i z e ) ; 
 
                         } 
 
                         e l s e 
 
                         { 
 
                                 t h i s . _ d i s t _ f a c t o r   =   n u l l ; 
 
                         } 
 
                         / /   *0000
 
                         t h i s . _ p c a   =   n e w   N y A R P c a 2 d _ M a t r i x P C A _ O 2 ( ) ; 
 
                         t h i s . _ x p o s   =   n e w   d o u b l e [ i _ s i z e . w   +   i _ s i z e . h ] ; / /  g'Ywo0t h i s . _ w i d t h + t h i s . _ h e i g h t 
 
                         t h i s . _ y p o s   =   n e w   d o u b l e [ i _ s i z e . w   +   i _ s i z e . h ] ; / /  g'Ywo0t h i s . _ w i d t h + t h i s . _ h e i g h t 
 
                         r e t u r n ; 
 
                 } 
 
 
 
 
 
                 / * * 
 
                   *   S0n0peo00*퐹pƖTK00a y + b x + c = 0 n0v}_0{W0~0Y00
 
                   *   @ p a r a m   i _ s t 
 
                   *   v}{n0[ah0Y000*퐹pn0Y000000
 
                   *   @ p a r a m   i _ e d 
 
                   *   v}{n0[ah0Y000*퐹pn0B}N000000
 
                   *   @ p a r a m   i _ c o o r d 
 
                   *   *퐹pƖTn00000000
 
                   *   @ p a r a m   o _ l i n e 
 
                   *   v}_0SQ0S0000000
 
                   *   @ r e t u r n 
 
                   *   v}_n0{k0bRY00h00t r u e 0ԏW0~0Y00
 
                   *   @ 
 
                   * / 
 
                 p u b l i c   b o o l   c o o r d 2 L i n e ( i n t   i _ s t ,   i n t   i _ e d ,   N y A R I n t C o o r d i n a t e s   i _ c o o r d ,   N y A R L i n e a r   o _ l i n e ) 
 
                 { 
 
                         / / p0S_
 
                         i n t   n ,   s t ,   e d ; 
 
                         d o u b l e   w 1 ; 
 
                         i n t   c o o d _ n u m   =   i _ c o o r d . l e n g t h ; 
 
 
 
                         / / c"}:Sn0zl[
 
                         i f   ( i _ e d   > =   i _ s t ) 
 
                         { 
 
                                 / / p[ i ] K00p[ i + 1 ] ~0g0n0*L001 :Sk0B00h0M0
 
                                 w 1   =   ( d o u b l e ) ( i _ e d   -   i _ s t   +   1 )   *   0 . 0 5   +   0 . 5 ; 
 
                                 / / c"}:Sn0zl[
 
                                 s t   =   ( i n t ) ( i _ s t   +   w 1 ) ; 
 
                                 e d   =   ( i n t ) ( i _ e d   -   w 1 ) ; 
 
                         } 
 
                         e l s e 
 
                         { 
 
                                 / / p[ i ] K00p[ i + 1 ] ~0g0n0*L002 :Sk0RK00f0D00h0M0
 
                                 w 1   =   ( d o u b l e ) ( ( i _ e d   +   c o o d _ n u m   -   i _ s t   +   1 )   %   c o o d _ n u m )   *   0 . 0 5   +   0 . 5 ; 
 
                                 / / c"}:Sn0zl[
 
                                 s t   =   ( ( i n t ) ( i _ s t   +   w 1 ) )   %   c o o d _ n u m ; 
 
                                 e d   =   ( ( i n t ) ( i _ e d   +   c o o d _ n u m   -   w 1 ) )   %   c o o d _ n u m ; 
 
                         } 
 
                         / / c"}:Spe0x
 
                         i f   ( s t   < =   e d ) 
 
                         { 
 
                                 / / c"}:So01 :S
 
                                 n   =   e d   -   s t   +   1 ; 
 
                                 i f   ( t h i s . _ d i s t _ f a c t o r   ! =   n u l l ) 
 
                                 { 
 
                                         t h i s . _ d i s t _ f a c t o r . o b s e r v 2 I d e a l B a t c h ( i _ c o o r d . i t e m s ,   s t ,   n ,   t h i s . _ x p o s ,   t h i s . _ y p o s ,   0 ) ; 
 
                                 } 
 
                         } 
 
                         e l s e 
 
                         { 
 
                                 / / c"}:So02 :S
 
                                 n   =   e d   +   1   +   c o o d _ n u m   -   s t ; 
 
                                 i f   ( t h i s . _ d i s t _ f a c t o r   ! =   n u l l ) 
 
                                 { 
 
                                         t h i s . _ d i s t _ f a c t o r . o b s e r v 2 I d e a l B a t c h ( i _ c o o r d . i t e m s ,   s t ,   c o o d _ n u m   -   s t ,   t h i s . _ x p o s ,   t h i s . _ y p o s ,   0 ) ; 
 
                                         t h i s . _ d i s t _ f a c t o r . o b s e r v 2 I d e a l B a t c h ( i _ c o o r d . i t e m s ,   0 ,   e d   +   1 ,   t h i s . _ x p o s ,   t h i s . _ y p o s ,   c o o d _ n u m   -   s t ) ; 
 
                                 } 
 
                         } 
 
                         / /  }pen0x
 
                         i f   ( n   <   2 ) 
 
                         { 
 
                                 / /   n L02 NNg0m a t r i x . P C A 0{Y00S0h0o0g0M0j0D0n0g00000
 
                                 r e t u r n   f a l s e ; 
 
                         } 
 
                         / / ;NbRRgY000
 
                         N y A R D o u b l e M a t r i x 2 2   e v e c   =   t h i s . _ _ g e t S q u a r e L i n e _ e v e c ; 
 
                         d o u b l e [ ]   m e a n   =   t h i s . _ _ g e t S q u a r e L i n e _ m e a n ; 
 
 
 
 
 
                         t h i s . _ p c a . p c a ( t h i s . _ x p o s ,   t h i s . _ y p o s ,   n ,   e v e c ,   t h i s . _ _ g e t S q u a r e L i n e _ e v ,   m e a n ) ; 
 
                         o _ l i n e . a   =   e v e c . m 0 1 ; / /   l i n e [ i ] [ 0 ]   =   e v e c - > m [ 1 ] ; 
 
                         o _ l i n e . b   =   - e v e c . m 0 0 ; / /   l i n e [ i ] [ 1 ]   =   - e v e c - > m [ 0 ] ; 
 
                         o _ l i n e . c   =   - ( o _ l i n e . a   *   m e a n [ 0 ]   +   o _ l i n e . b   *   m e a n [ 1 ] ) ; / /   l i n e [ i ] [ 2 ]   =   - ( l i n e [ i ] [ 0 ] * m e a n - > v [ 0 ]   +   l i n e [ i ] [ 1 ] * m e a n - > v [ 1 ] ) ; 
 
 
 
                         r e t u r n   t r u e ; 
 
                 } 
 
         } 
 
 } 