﻿ Rotation- How does it work??
19 June, 2013, 19:38:24
 OmnomIRC You must Register, be logged in and have at least 40 posts to use this shout-box! If it still doesn't show up afterward, it might be that OmnomIRC is disabled for your group or under maintenance.Note: You can also use an IRC client like mIRC, X-Chat or Mibbit to connect to an EFnet server and #omnimaga.

 Pages: 1 [2] 3   Go Down
 Author Topic: Rotation- How does it work?? -  (Read 1047 times) 0 Members and 1 Guest are viewing this topic.
Builderboy
Physics Guru

Offline

Gender:
Date Registered: 20 April, 2009, 00:28:53
Location: Ravenholm
Posts: 5645

Total Post Ratings: +589

 « Reply #15 on: 13 March, 2012, 20:12:32 » +1

That is because you typed it in wrong You should be using this code:

 12 x = (sp[c].X-xc)*cosd(d) - (sp[c].Y-yc)*sind(d) + xc;y = (sp[c].X-xc)*sind(d) + (sp[c].Y-yc)*cosd(d) + yc;

 Logged

nxtboy III

Offline

Last Login: 22 May, 2013, 02:53:41
Date Registered: 30 March, 2011, 22:57:58
Posts: 784

Topic starter
Total Post Ratings: +23

 « Reply #16 on: 13 March, 2012, 20:40:01 » 0

Yeah, I did that and added some parentheses and BOOM!!! It worked!!!! Thanks!!
 Logged

Builderboy
Physics Guru

Offline

Gender:
Date Registered: 20 April, 2009, 00:28:53
Location: Ravenholm
Posts: 5645

Total Post Ratings: +589

 « Reply #17 on: 13 March, 2012, 20:44:22 » 0

Yay! Glad I could help ^^
 Logged

nxtboy III

Offline

Last Login: 22 May, 2013, 02:53:41
Date Registered: 30 March, 2011, 22:57:58
Posts: 784

Topic starter
Total Post Ratings: +23

 « Reply #18 on: 13 March, 2012, 20:46:45 » 0

I tried rotating a picture by getting all the points. It works, but is really slow. Could I speed this up?
 Logged

Builderboy
Physics Guru

Offline

Gender:
Date Registered: 20 April, 2009, 00:28:53
Location: Ravenholm
Posts: 5645

Total Post Ratings: +589

 « Reply #19 on: 13 March, 2012, 20:48:23 » 0

The best thing you could do would be to move the cos() and sin() outside the loop, since you really only need to calculate them once per rotation.  Just precalculate them, place them into variables of their own, and use those variables instead
 Logged

nxtboy III

Offline

Last Login: 22 May, 2013, 02:53:41
Date Registered: 30 March, 2011, 22:57:58
Posts: 784

Topic starter
Total Post Ratings: +23

 « Reply #20 on: 13 March, 2012, 20:49:33 » 0

I tried that, but for some odd reason, it messes up.
 Logged

Builderboy
Physics Guru

Offline

Gender:
Date Registered: 20 April, 2009, 00:28:53
Location: Ravenholm
Posts: 5645

Total Post Ratings: +589

 « Reply #21 on: 13 March, 2012, 20:55:57 » 0

 Logged

nxtboy III

Offline

Last Login: 22 May, 2013, 02:53:41
Date Registered: 30 March, 2011, 22:57:58
Posts: 784

Topic starter
Total Post Ratings: +23

 « Reply #22 on: 13 March, 2012, 20:57:57 » 0

Ok.
 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134 float magnitude(int x1,int y1,int x2,int y2){ return(sqrt(pow(x2-x1,2) + pow(y2-y1,2)));}struct floatpoint{ float X; float Y;};byte Data[];byte Line;byte offset;//LocationType poly[] = {{10,10},{//LocationType sp[]={{10,10},{10,30},{5,27},{10,30},{15,27},{10,30},{10,25},{5,22},{10,25},{15,22},{10,25},{10,20},{5,17},{10,20},{15,17},{10,20}};floatpoint spf[];byte __ips_masks[] = {0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01};byte isPixelSet(byte Xx, byte Yy){  Line = (63-Yy & 0xF8) / 8;  offset = Yy % 8;  GetDisplayNormal(Xx, Line, 1, Data);  return Data[0] & __ips_masks[offset];}task main(){ float x,y; int xc,yc;// int dis; //x=0; //y=50; xc= 40; yc=40; float deg; int d; //float dis[]; float c,s; int xt1,yt1,xt2,yt2; int l; //int arrs = ArrayLen(sp); int bul = 0;// ArrayInit(dis,0,arrs);// ArrayInit(spf,0,arrs);//RectOut(50,50,3,3);GraphicOut(50,40,"squirt.ric"); for(int c=0; c < 100; c++) {  for(int d=0; d < 64; d++)  {   if(isPixelSet(c,d))   {    l++;   }  } } ArrayInit(spf,0,l);  for(int c=0; c < 100; c++) {  for(int d=0; d < 64; d++)  {   if(isPixelSet(c,d))   {    spf[bul].X = c;    spf[bul].Y = d;    bul++;   }  } } PlayToneEx(600,30,1,0);/*   for(int c=0; c < l; c++)  {  // dis[c] = magnitude(xc,yc,sp[c].X,sp[c].Y);   //sp[c].X += 30;   //sp[c].Y += 30;   if(   spf[c].X = sp[c].X;   spf[c].Y = sp[c].Y;   }*/ while(1) { // x=x*(cosd(30))-y*(sind(30));  //y=x*(sind(30))+y*(cosd(30)); // x = cosd(deg--)*magnitude(0,0,x,y); // y = sind(deg)*magnitude(0,0,x,y); // x -= xc;  //y -= yc;  c = cosd(d);  s = sind(d);  for(int c=0; c < l; c++)  { // deg = atan2d((sp[c].Y-yc),(sp[c].X-xc));  // xt1 = ((spf[c].X - xc) * c);   //yt1 = ((spf[c].Y - yc) * s);   //xt2 = ((spf[c].X - xc) * s);   //yt2 = ((spf[c].Y - yc) * c);   //x = (xt1 - yt1) + xc;   //y = (xt2 + yt2) + yc;  // x = sqrt(pow((spf[c].X - xc),2) + pow((spf[c].Y - yc),2))*cosd(atand(spf[c].X - xc)/(spf[c].Y - yc)+ 5)+ xc;  // y = sqrt(pow((spf[c].X - xc),2) + pow((spf[c].Y - yc),2))*sind(atand(spf[c].X - xc)/(spf[c].Y - yc)+ 5)+ yc;  //y = dis[c]*sind(deg + 3)+yc;  x = ((spf[c].X-xc)*c) - ((spf[c].Y-yc)*s) + xc;  y = ((spf[c].Y-yc)*c) + ((spf[c].X-xc)*s) + yc;  spf[c].X = x;  spf[c].Y = y;  //sp[c].X=spf[c].X;  //sp[c].Y=spf[c].Y;  }  if(ButtonPressed(BTNRIGHT,0))  d = -5;  else  d = 0; // sp[0].X=1;  //CircleOut(x,y,10);//  PolyOut(sp);SetDisplayFlags( DISPLAY_REFRESH_DISABLED);  ClearScreen();  for(int c=0; c < l; c++)  {   PointOut(spf[c].X,spf[c].Y);  }   //PolyOut(sp);  SetDisplayFlags( DISPLAY_ON | DISPLAY_REFRESH);  Wait(17); }}
 Logged

Builderboy
Physics Guru

Offline

Gender:
Date Registered: 20 April, 2009, 00:28:53
Location: Ravenholm
Posts: 5645

Total Post Ratings: +589

 « Reply #23 on: 13 March, 2012, 21:00:11 » 0

For future reference you only have to post the relevant part of your code, not the whole thing Could it be that the issue is coming from the fact that your for loop variable is also named C?
 Logged

nxtboy III

Offline

Last Login: 22 May, 2013, 02:53:41
Date Registered: 30 March, 2011, 22:57:58
Posts: 784

Topic starter
Total Post Ratings: +23

 « Reply #24 on: 13 March, 2012, 21:02:31 » 0

Wow, I can't believe I did not think of that!! Now it works.
Though it doesn't seem to go much faster.

You should help me program stuff...
 « Last Edit: 13 March, 2012, 21:02:48 by nxtboy III » Logged

Builderboy
Physics Guru

Offline

Gender:
Date Registered: 20 April, 2009, 00:28:53
Location: Ravenholm
Posts: 5645

Total Post Ratings: +589

 « Reply #25 on: 13 March, 2012, 21:03:36 » 0

Yeah rotation is slow in general without stuff like Graphics Cards :[ unfortunately I don't think you will be able to get much faster than you have it currently.
 Logged

nxtboy III

Offline

Last Login: 22 May, 2013, 02:53:41
Date Registered: 30 March, 2011, 22:57:58
Posts: 784

Topic starter
Total Post Ratings: +23

 « Reply #26 on: 13 March, 2012, 21:05:09 » 0

yeah....
But you seem to be good at this language. You should help me with other stuff...
 Logged

Builderboy
Physics Guru

Offline

Gender:
Date Registered: 20 April, 2009, 00:28:53
Location: Ravenholm
Posts: 5645

Total Post Ratings: +589

 « Reply #27 on: 13 March, 2012, 21:06:53 » 0

On the contrary I have little knowledge about that language, you were just lucky the issues you were having were general issues and not programming specific issues.  And if you ever have any more issues feel free to post about them and I will see what I can do ^^
 Logged

nxtboy III

Offline

Last Login: 22 May, 2013, 02:53:41
Date Registered: 30 March, 2011, 22:57:58
Posts: 784

Topic starter
Total Post Ratings: +23

 « Reply #28 on: 13 March, 2012, 21:14:47 » 0

ok, sure.
 Logged

christop
LV3 Member (Next: 100)

Offline

Gender:
Last Login: 13 April, 2013, 04:04:55
Date Registered: 26 February, 2011, 19:58:44
Location: Arizona, USA
Posts: 87

Total Post Ratings: +20

 « Reply #29 on: 13 March, 2012, 21:43:23 » 0

I tried rotating a picture by getting all the points. It works, but is really slow. Could I speed this up?
Are you trying to rotate a raster (bitmap) image? That's understandably going to slow because a raster image contains many points.

It might be a lot quicker to rotate it by shearing the bitmap three times: http://www.ocf.berkeley.edu/~fricke/projects/israel/paeth/rotation_by_shearing.html

Or you could try using fixed-point instead of floating-point arithmetic using your current algorithm because your system might not have floating-point hardware, so it has to be emulated in software (which is slooooow).
 Logged

Christopher Williams
 Pages: 1 [2] 3   Go Up