Created
October 14, 2014 16:04
-
-
Save hirosof/4105777e30c83b711427 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "HSFigure.h" | |
HSBoldLinePoints HSCalcLinePointForConnectTwoCircle(HSCircle c1, HSCircle c2, double LineThickPercent) { | |
//戻り値を収納する共用体 | |
HSBoldLinePoints hsbp; | |
//上側の円と下側の円のポインタ | |
HSCircle *pUpper, *pBelow; | |
//左側の円と右側の円のポインタ | |
HSCircle *pLeft, *pRight; | |
/* | |
初期設定 | |
*/ | |
//戻り値用の共用体初期化 | |
for (int i = 0; i < (sizeof(hsbp.Point) / sizeof(HSPosition)); i++) { | |
hsbp.Point[i].x = 0; | |
hsbp.Point[i].y = 0; | |
} | |
//パラメータの2つの円を上下に識別する | |
if (c1.CorePos.y >= c2.CorePos.y) { | |
pUpper = &c1; | |
pBelow = &c2; | |
} else { | |
pUpper = &c2; | |
pBelow = &c1; | |
} | |
//パラメータの2つの円を左右に識別する | |
if (c1.CorePos.x >= c2.CorePos.x) { | |
pRight = &c1; | |
pLeft = &c2; | |
} else { | |
pRight = &c2; | |
pLeft = &c1; | |
} | |
/* | |
共通準備・計算 | |
*/ | |
//2つの円の距離 | |
HSPosition Distance; | |
//2つの円の中心を線で結んだ時の角度(θ) | |
double Theta; | |
//θを基準に反時計回りで直角に交わるときの角度(θ+90度) | |
double LeftTheta; | |
//θを基準に時計回りで直角に交わるときの角度(θ-90度) | |
double RightTheta; | |
//単位円上においての位置 | |
HSPosition OnUnitCircleByLeftTheta; | |
HSPosition OnUnitCircleByRightTheta; | |
//距離を計算 | |
Distance.x = pRight->CorePos.x - pLeft->CorePos.x; | |
Distance.y = pUpper->CorePos.y - pBelow->CorePos.x; | |
//角度を取得 | |
Theta = atan2(Distance.y, Distance.x); | |
//θを基準に反時計回りで直角に交わるときの角度を計算 | |
LeftTheta = Theta + M_PI / 2.0; | |
//θを基準に時計回りで直角に交わるときの角度を計算 | |
RightTheta = Theta - M_PI / 2.0; | |
//単位円上においての位置を計算 | |
OnUnitCircleByLeftTheta.x = cos(LeftTheta); | |
OnUnitCircleByLeftTheta.y = sin(LeftTheta); | |
OnUnitCircleByRightTheta.x = cos(RightTheta); | |
OnUnitCircleByRightTheta.y = sin(RightTheta); | |
/* | |
上側の円についての計算 | |
*/ | |
//上側の円の直径の LineThickPercent パーセントの長さ | |
double LengthOfLineInUpperCircle = pUpper->Radius * LineThickPercent / 50.0; | |
//上部・左側の位置の計算 | |
hsbp.Detail.TopLeft.x = LengthOfLineInUpperCircle / 2.0 * OnUnitCircleByLeftTheta.x + pUpper->CorePos.x; | |
hsbp.Detail.TopLeft.y = LengthOfLineInUpperCircle / 2.0 * OnUnitCircleByLeftTheta.y + pUpper->CorePos.y; | |
//上部・右側の位置の計算 | |
hsbp.Detail.TopRight.x = LengthOfLineInUpperCircle / 2.0 * OnUnitCircleByRightTheta.x + pUpper->CorePos.x; | |
hsbp.Detail.TopRight.y = LengthOfLineInUpperCircle / 2.0 * OnUnitCircleByRightTheta.y + pUpper->CorePos.y; | |
/* | |
下側の円についての計算 | |
*/ | |
//下側の円の直径の LineThickPercent パーセントの長さ | |
double LengthOfLineInBelowCircle = pBelow->Radius * LineThickPercent / 50.0; | |
//下部・左側の位置の計算 | |
hsbp.Detail.BottomLeft.x = LengthOfLineInBelowCircle / 2.0 * OnUnitCircleByLeftTheta.x + pBelow->CorePos.x; | |
hsbp.Detail.BottomLeft.y = LengthOfLineInBelowCircle / 2.0 * OnUnitCircleByLeftTheta.y + pBelow->CorePos.y; | |
//下部・右側の位置の計算 | |
hsbp.Detail.BottomRight.x = LengthOfLineInBelowCircle / 2.0 * OnUnitCircleByRightTheta.x + pBelow->CorePos.x; | |
hsbp.Detail.BottomRight.y = LengthOfLineInBelowCircle / 2.0 * OnUnitCircleByRightTheta.y + pBelow->CorePos.y; | |
return hsbp; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef __HSFIGURE__ | |
#define __HSFIGURE__ | |
#define _USE_MATH_DEFINES | |
#include <stdio.h> | |
#include <math.h> | |
struct HSPosition { | |
double x; //X座標 | |
double y; //Y座標 | |
}; | |
struct HSCircle { | |
HSPosition CorePos; //中心座標 | |
double Radius; //半径 | |
}; | |
union HSBoldLinePoints { | |
struct Named { | |
HSPosition TopLeft; //上部・左の座標 | |
HSPosition TopRight; //上部・右の座標 | |
HSPosition BottomRight; //下部・右の座標 | |
HSPosition BottomLeft; //下部・左の座標 | |
}Detail; | |
HSPosition Point[4]; //4点の座標 | |
}; | |
HSBoldLinePoints HSCalcLinePointForConnectTwoCircle(HSCircle c1, HSCircle c2, double LineThickPercent); | |
#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment