java - Calculating points on a circle for 3D rotation -


so decided play around basic 3d. wanted start having cube 1 screen , able rotate cube in directions. i'm starting rotating on x plane. the issue i'm having 2 points @ top , bottom of cube (being points near 0-180º mark) moving faster of rest. more explanation after.

public integer[] circlemath(int rotation, int x_rot, double main_x, double main_z){     double d = math.sqrt(math.pow(100, 2) * 2); // calculating diametre of circle. ends around 141      int tx_rot = x_rot + rotation; // each point has offset in rotation main cube, these @ intervals of 90ª     boolean on = false; // deciding if use positive or negative result sqr     if (tx_rot >= 360){ tx_rot -= 360; } // occurs when rotation offset added     if (tx_rot > 180){ tx_rot = 360 - tx_rot; on = true; } // has gone past 180 degrees, use neg result sqr      double z = (main_z - (tx_rot * d / 180) + (d/2)); // explained below (1)     double x = (math.sqrt(math.pow(d / 2, 2) - math.pow(z - main_z, 2))); // uses x^2 + y^2 == r^2     if (over){ x *= -1; } // neg result      // returning values     integer ret[] = new integer[2];     ret[0] = (int) math.round((x + main_x));     ret[1] = (int) math.round(z);     return ret;  } 

this function i'm using calculate points @ various areas. basic logic follows.

  1. calculate z based off x_rot (the rotation of object)
  2. use y value find x (x^2 + y^2 = r^2)

calculating z consists of dividing diameter of circle 180 (180º), rest self-explanatory.

here results recorded.

tx_rot: 175 x: -23.240556292613196 z: -66.78230711206282 tx_rot: 176 x: -20.846292265881893 z: -67.56798131338121 tx_rot: 177 x: -18.104634152000347 z: -68.3536555146996 tx_rot: 178 x: -14.824071182362571 z: -69.13932971601798 tx_rot: 179 x: -10.511604404680254 z: -69.92500391733637 tx_rot: 180 x: 0.0 z: -70.71067811865476 

you can see z constant in decreasing ~0.7 x seems exponential-ish. when tx_rot 180, z reaches radius perfect , x expected bottom out.

any ideas why x inconsistent appreciated.

let me know if need anymore information, i've got no clue what's wrong

what looks @ 0º rotation :)


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -