#include "MyFunction.h" Vec2 ConvertMath2Screen(Vec2 _point) { Vec2 resultPoint; Vec2 halfScrSize = { Scene::Width() / 2.0, Scene::Height() / 2.0 }; resultPoint.x = _point.x + halfScrSize.x; resultPoint.y = Scene::Height() - (_point.y + halfScrSize.y); return resultPoint; } Vec2 ConvertScreen2Math(Vec2 _point) { Vec2 resultPoint; Vec2 halfScrSize = { Scene::Width() / 2.0, Scene::Height() / 2.0 }; resultPoint.x = _point.x - halfScrSize.x; resultPoint.y = Scene::Height() - _point.y - halfScrSize.y; return resultPoint; } double Degree2Radians(double _angle) { return(_angle * (PI / 180.0)); } void DrawAxis() { Vec2 halfScrSize = { Scene::Width() / 2.0, Scene::Height() / 2.0 }; Vec2 xAxisStart = { 0, halfScrSize.y }; Vec2 xAxisEnd = { Scene::Width() , halfScrSize.y }; Vec2 yAxisStart = { halfScrSize.x, Scene::Height() }; Vec2 yAxisEnd = { halfScrSize.x, 0 }; Line{ xAxisStart, xAxisEnd }.drawArrow(2, Vec2{ 5,5 }, Palette::Black); Line{ yAxisStart, yAxisEnd }.drawArrow(2, Vec2{ 5,5 }, Palette::Black); } Vec2 RotateVec(Vec2 _vec, double _angle) { double theta = Degree2Radians(_angle); //ラジアン Vec2 res; res.x = _vec.x * cos(theta) - _vec.y * sin(theta); res.y = _vec.x * sin(theta) + _vec.y * cos(theta); return(res); } void SetEquTrianglePoint(triangle& _tri, double _length) { _tri.length = _length; _tri.pos[1].x = -_length / 2; _tri.pos[1].y = 0; _tri.pos[2].x = _length / 2; _tri.pos[2].y = 0; _tri.pos[0].x = 0.0; _tri.pos[0].y = _length * sin(Degree2Radians(60)); double bias = _length * sin(Degree2Radians(60)) * (1 / 3.0); //高さの1/3を求めてる for (int i = 0; i < 3; i++) _tri.pos[i].y -= bias;//全y座標高さの1/3下げる } Vec2 GetShortestPoint(triangle& _tri, Vec2 _cp) { double dist[3]; for (int i = 0; i < 3; i++) dist[i] = sqrt((_tri.pos[i].x - _cp.x) * (_tri.pos[i].x - _cp.x) + (_tri.pos[i].y - _cp.y) * (_tri.pos[i].y - _cp.y)); int mini = 0; for (int i = 0; i < 3; i++) { if (dist[mini] > dist[i]) mini = i; } return(_tri.pos[mini]); }