Rotate all Ipoints (iGeo library)

Hi everyone!

I can’t seem to figure out how I can rotate my cube made out of iPoints. I guess I have to rotate each point around a pivitpoint which i place in the middle of all the iPoints. Can anyone give me a tip or help me out a bit?

Thank you so much!

import igeo.*;
import igeo.gui.*;
import igeo.io.*;
import igeo.p.*;


IPoint cube;
int i2, k2, j2;


void setup(){
  background(0);
  size( 600, 400, IG.GL );
  i2 = 10;
  k2 = 10;
  j2 = 10;
  
  background(0);
}

void draw () {
  //i2 += 1;
  //k2 += 1;
  //j2 += 1;
  drawCube();
}

void drawCube() {
  for(int i=0; i < 15; i++){
    for(int j=0; j < 15; j++){
      for(int k=0; k < 15; k++){
        cube = new IPoint(i*i2, j*j2, k*k2).clr(i*0.1, j*0.1, k*0.1);
      }
    }
  }
}

Hi,

Welcome to the forum! :wink:

Can you please format your code by using the </> button when editing a message on the forum or use back ticks around your code : ```code``` → code

I’ve never used the iGeo library but I suppose you can use the Processing’s transformation functions like translate() or rotate().

If you are new to this, I suggest you look at the tutorial on transforms in 2D (which can generalize in 3D as well) :

https://processing.org/tutorials/transform2d/

And also for 3d :

https://processing.org/tutorials/p3d/

I haven’t tested (again, please format the code as joseph wrote) but I guess rot is the function you are looking for. It seems it returns another IPoint but not sure if it affects the original point instance.
http://igeo.jp/doc/igeo/IPoint.html#rot(double,%20double,%20double,%20double,%20double,%20double,%20double)

(by the way Satoru the author of the library gave a keynote at our PCD last year :slight_smile:)

1 Like