Project

General

Profile

Download (7.54 KB) Statistics
| Branch: | Revision:

distorted-objectlib / src / main / java / org / distorted / objectlib / main / Movement12.java @ ab31cf6f

1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2020 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Magic Cube.                                                              //
5
//                                                                                               //
6
// Magic Cube is free software: you can redistribute it and/or modify                            //
7
// it under the terms of the GNU General Public License as published by                          //
8
// the Free Software Foundation, either version 2 of the License, or                             //
9
// (at your option) any later version.                                                           //
10
//                                                                                               //
11
// Magic Cube is distributed in the hope that it will be useful,                                 //
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of                                //
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                                 //
14
// GNU General Public License for more details.                                                  //
15
//                                                                                               //
16
// You should have received a copy of the GNU General Public License                             //
17
// along with Magic Cube.  If not, see <http://www.gnu.org/licenses/>.                           //
18
///////////////////////////////////////////////////////////////////////////////////////////////////
19

    
20
package org.distorted.objectlib.main;
21

    
22
import static org.distorted.objectlib.main.TwistyObject.SQ5;
23

    
24
import org.distorted.library.type.Static3D;
25

    
26
///////////////////////////////////////////////////////////////////////////////////////////////////
27
// Dodecahedral objects: map the 2D swipes of user's fingers to 3D rotations
28

    
29
public class Movement12 extends Movement
30
{
31
  public static final float C2       = (SQ5+3)/4;
32
  public static final float LEN      = (float)(Math.sqrt(1.25f+0.5f*SQ5));
33
  public static final float SIN54    = (SQ5+1)/4;
34
  public static final float COS54    = (float)(Math.sqrt(10-2*SQ5)/4);
35

    
36
  public  static final float DIST3D = (float)Math.sqrt(0.625f+0.275f*SQ5);
37
  private static final float DIST2D = (SIN54/COS54)/2;
38
  private static final float[] D3D  = { DIST3D,DIST3D,DIST3D,DIST3D,DIST3D,DIST3D,
39
                                        DIST3D,DIST3D,DIST3D,DIST3D,DIST3D,DIST3D };
40

    
41
  public static final Static3D[] FACE_AXIS = new Static3D[]
42
         {
43
           new Static3D(    C2/LEN, SIN54/LEN,    0      ),
44
           new Static3D(    C2/LEN,-SIN54/LEN,    0      ),
45
           new Static3D(   -C2/LEN, SIN54/LEN,    0      ),
46
           new Static3D(   -C2/LEN,-SIN54/LEN,    0      ),
47
           new Static3D( 0        ,    C2/LEN, SIN54/LEN ),
48
           new Static3D( 0        ,    C2/LEN,-SIN54/LEN ),
49
           new Static3D( 0        ,   -C2/LEN, SIN54/LEN ),
50
           new Static3D( 0        ,   -C2/LEN,-SIN54/LEN ),
51
           new Static3D( SIN54/LEN,    0     ,    C2/LEN ),
52
           new Static3D( SIN54/LEN,    0     ,   -C2/LEN ),
53
           new Static3D(-SIN54/LEN,    0     ,    C2/LEN ),
54
           new Static3D(-SIN54/LEN,    0     ,   -C2/LEN )
55
         };
56

    
57
///////////////////////////////////////////////////////////////////////////////////////////////////
58

    
59
  public Movement12(Static3D[] rotAxis,float[][] cuts, boolean[][] rotatable, float size, int type, int[][][] enabled)
60
    {
61
    super(rotAxis, FACE_AXIS, cuts,rotatable,D3D, size, type, enabled);
62
    }
63

    
64
///////////////////////////////////////////////////////////////////////////////////////////////////
65

    
66
  public float returnRotationFactor(int[] numLayers, int row)
67
    {
68
    return 1.0f;
69
    }
70

    
71
///////////////////////////////////////////////////////////////////////////////////////////////////
72
// return angle (in radians) that the line connecting the center C of the pentagonal face and the
73
// first vertex of the pentagon makes with a vertical line coming upwards from the center C.
74

    
75
  private float returnAngle(int face)
76
    {
77
    switch(face)
78
      {
79
      case  0:
80
      case  2:
81
      case  6:
82
      case  7: return 0.0f;
83
      case  1:
84
      case  3:
85
      case  4:
86
      case  5: return (float)(36*Math.PI/180);
87
      case  9:
88
      case 10: return (float)(54*Math.PI/180);
89
      case  8:
90
      case 11: return (float)(18*Math.PI/180);
91
      }
92

    
93
    return 0.0f;
94
    }
95

    
96
///////////////////////////////////////////////////////////////////////////////////////////////////
97
// The pair (distance,angle) defines a point P in R^2 in polar coordinate system. Let V be the vector
98
// from the center of the coordinate system to P.
99
// Let P' be the point defined by polar (distance,angle+PI/2). Let Lh be the half-line starting at
100
// P' and going in the direction of V.
101
// Return true iff point 'point' lies on the left of Lh, i.e. when we rotate (using the center of
102
// the coordinate system as the center of rotation) 'point' and Lh in such a way that Lh points
103
// directly upwards, is 'point' on the left or the right of it?
104

    
105
  private boolean isOnTheLeft(float[] point, float distance, float angle)
106
    {
107
    float sin = (float)Math.sin(angle);
108
    float cos = (float)Math.cos(angle);
109

    
110
    float vx = point[0] + sin*distance;
111
    float vy = point[1] - cos*distance;
112

    
113
    return vx*sin < vy*cos;
114
    }
115

    
116
///////////////////////////////////////////////////////////////////////////////////////////////////
117

    
118
  int returnPart(int type, int face, float[] point)
119
    {
120
    switch(type)
121
      {
122
      case TYPE_SPLIT_EDGE  : return partEdge(point,face);
123
      case TYPE_SPLIT_CORNER: return partCorner(point,face);
124
      default               : return 0;
125
      }
126
    }
127

    
128
///////////////////////////////////////////////////////////////////////////////////////////////////
129
// Return 0,1,2,3,4 - the vertex of the pentagon to which point 'point' is the closest, if the
130
// 'point' is inside the pentagon - or -1 otherwise.
131
// The 'first' vertex is the one we meet the first when we rotate clockwise starting from 12:00.
132
// This vertex makes angle 'returnAngle()' with the line coming out upwards from the center of the
133
// pentagon.
134
// Distance from the center to a vertex of the pentagon = 1/(6*COS54)
135

    
136
  int partEdge(float[] point, int face)
137
    {
138
    float angle = returnAngle(face);
139
    float A = (float)(Math.PI/5);
140

    
141
    for(int i=0; i<5; i++)
142
      {
143
      if( isOnTheLeft(point, DIST2D, (9-2*i)*A-angle) ) return -1;
144
      }
145

    
146
    if( isOnTheLeft(point, 0, 2.5f*A-angle) )
147
      {
148
      if( isOnTheLeft(point, 0, 3.5f*A-angle) )
149
        {
150
        return isOnTheLeft(point, 0, 5.5f*A-angle) ? 3 : 4;
151
        }
152
      else return 0;
153
      }
154
    else
155
      {
156
      if( isOnTheLeft(point, 0, 4.5f*A-angle) )
157
        {
158
        return 2;
159
        }
160
      else
161
        {
162
        return isOnTheLeft(point, 0, 6.5f*A-angle) ? 1 : 0;
163
        }
164
      }
165
    }
166

    
167
///////////////////////////////////////////////////////////////////////////////////////////////////
168
// TODO - no such object yet
169

    
170
  int partCorner(float[] point, int face)
171
    {
172
    return 0;
173
    }
174

    
175
///////////////////////////////////////////////////////////////////////////////////////////////////
176

    
177
  boolean isInsideFace(int face, float[] p)
178
    {
179
    float angle = returnAngle(face);
180
    float A = (float)(Math.PI/5);
181

    
182
    for(int i=0; i<5; i++)
183
      {
184
      if( isOnTheLeft(p, DIST2D, (9-2*i)*A-angle) ) return false;
185
      }
186

    
187
    return true;
188
    }
189
}
(3-3/16)