Project

General

Profile

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

distorted-objectlib / src / main / java / org / distorted / objectlib / main / Movement12.java @ 8da6b1c9

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

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

    
55
///////////////////////////////////////////////////////////////////////////////////////////////////
56

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

    
62
///////////////////////////////////////////////////////////////////////////////////////////////////
63

    
64
  public float returnRotationFactor(int numLayers, int row)
65
    {
66
    return 1.0f;
67
    }
68

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

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

    
91
    return 0.0f;
92
    }
93

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

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

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

    
111
    return vx*sin < vy*cos;
112
    }
113

    
114
///////////////////////////////////////////////////////////////////////////////////////////////////
115

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

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

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

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

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

    
165
///////////////////////////////////////////////////////////////////////////////////////////////////
166
// TODO - no such object yet
167

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

    
173
///////////////////////////////////////////////////////////////////////////////////////////////////
174

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

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

    
185
    return true;
186
    }
187
}
(3-3/15)