【问题标题】:Finding angle rectangle will occupy when drawn along circle (see drawing)沿圆形绘制时,寻找角度矩形将占据(见图)
【发布时间】:2012-09-01 21:48:05
【问题描述】:

这就是我想要做的。我有一个字体,基本上是每个字形的位图矩形。我正在尝试获得这样的弧形文本效果:

我的计划是,给定一个中心和一个半径,我将求解每个字形的位置和角度。

我有一个可以找到位置的函数:

Vec2 Math::positionFromCenterToLineAt( Vec2 center, float dist,
        float totalAngular, float angularDistance, float angularOffset )
    {
        float startAngle = -((totalAngular) / 2.0f);
        float curAngle = startAngle + angularDistance;
        curAngle -= angularOffset;
        curAngle += angularDistance / 2.0f;
        curAngle += CGE_PI;

        Vec2 retVec = center;
        Vec2 angVec = Vec2(sin(curAngle),cos(curAngle));
        angVec *= dist;
        retVec += angVec;

        return retVec;
    }

它需要我知道圆的弧度将占据多少,并且需要从开始角度绘制当前字形的角度。

在给定字形的半径、中心、宽度和高度的情况下,我想不出一个函数来查找给定字形将占据的角度。每个字形可以有不同的维度。

看到这个:

如您所见,我正在寻找圆的弧度。

如何计算?

谢谢

【问题讨论】:

  • 你要计算each pie of char的角度吗?
  • 我想计算每个字符占据的圆的弧度。

标签: c++ algorithm geometry


【解决方案1】:
2*pi*radius equals the circumference
You know radius as a pixel base(lets say it is 40 pixels)
You can find circumference(lets say it is 251 pixels)
Then, if you get width of a char(lets say it is 8)
You know the angle of arc: angle=2*pi*(8/251)=2*pi*0.03=0.2 radians
0.2 radians * 57.3 = 11.5 degrees

如何根据当前字体查找字符的宽度?

LOGFONT lf;
int width=lf.lfWidth; //beware! this is average

你想要精确的选择吗?

GetTextExtentPoint32() // search usage of this!

Its structure type is:

 BOOL GetTextExtentPoint32(
  __in   HDC hdc,
  __in   LPCTSTR lpString,
  __in   int c,
  __out  LPSIZE lpSize
);

【讨论】:

  • 我使用的是使用 FreeType 的 TTF 字体,这给了我准确的宽度。不过还是谢谢。
  • 我也喜欢trutypefont!我在 FRP 的主机游戏中使用过一次。但只能用于 Turbo-C++
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-07-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多