Skip to content

Instantly share code, notes, and snippets.

@tacke758
Created June 19, 2013 06:32
Show Gist options
  • Save tacke758/5812078 to your computer and use it in GitHub Desktop.
Save tacke758/5812078 to your computer and use it in GitHub Desktop.
UltraCで楕円を回転させて描画する関数
#include <stdio.h>
#include "graphic.h"
#include "math.h"
#define PARTITION 40
/**
* 楕円を回転させて描画する
* a 長辺の長さ
* b 短辺の長さ
* phi 回転角(度) x軸を母線として時計回り
* rx 中心のx座標
* ry 中心のy座標
*/
void DrawRotateEllipse(int a, int b, float phi, int rx, int ry) {
POINT p[PARTITION];
int i;
float theta;
float pi = 3.141592;
phi = 2 * pi * (phi / 360); // convert degree to radian
for (i = 0; i < PARTITION; i ++) {
theta = (2 * pi / PARTITION) * i;
p[i].x = (int)(a * cos(phi) * cos(theta) - b * sin(phi) * sin(theta) + rx);
p[i].y = (int)(a * sin(phi) * cos(theta) + b * cos(phi) * sin(theta) + ry);
}
DrawPolygon(p, PARTITION, BLUE, PSOLID, 1, BLUE, BSOLID, 0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment