1

我期待将具有固定轴的矩形旋转为铰链的数学或算法计算。如下图所示。

我有 4 个矩形顶点的位置 (x,y),原点是矩形的中心,因此所需的算法会将我的原始形状的顶点投影到所需的形状顶点中。(请看下图)

我知道用 3d 库很容易做到这一点,但我需要用 .Net 或 JAVA 等高级编程语言或没有任何 3d 或补充库的东西用 2d 图形来做。

请帮助我提供任何想法或参考,或者比所有源代码或算法更好。

在此处输入图像描述

提前感谢您的优质时间。

4

2 回答 2

4

总结一下我上面的评论:

于 2012-05-28T00:23:50.760 回答
2

根据我的经验,在处理二维时,我发现使用一种称为处理的出色工具取得了巨大的成功. 处理是 Java 编程语言的扩展,专门针对任何事物的可视化,从数据结构到令人生畏的物理模拟。从您提供的有用图形中,我假设您想在任何给定时间围绕一个点或轴旋转一个结构。看看功能丰富的 API 参考,处理报价(我是新用户,很遗憾我不能链接两个以上的项目,将在下面放 API 参考的链接)。它们具有围绕点旋转和变换的独特功能。但是,它不会围绕所述点旋转结构,而是围绕该点旋转整个屏幕及其包含的所有内容。例如,如果你想将所有东西都围绕原点 (0,0) 旋转 45 度,它很简单:

void setup()
{
  size(200, 200); // Set the size of the screen to 200 x 200 pixels
  background(255); // Set the background to white
  smooth(); // Smooth the edges of the rectangles
  fill(192); // Fill the rectangle with a light gray
  noStroke(); // No black border on rectangle
  rect(40, 40, 40, 40); // Create an equilateral rectangle (square) that is 40 x 40 pixels at the point (40,40)

  pushMatrix(); //Let the compiler know that you will be modifying the Matrix
  rotate(radians(45)); // Rotate the screen about the origin (by default) 45 degrees clockwise
  fill(0); // Color the following rectangle black
  rect(40, 40, 40, 40); // Draw an equivalent rectangle as the last one, only at the new modified screen coordinates
  popMatrix(); // Let the compiler know you are done modifying the matrix
}

上面的代码将创建两个相同的正方形,一个在点 (40,40),一个在原点顺时针 45 度处。

有一个非常详细的教程可以在这里找到,它更详细地解释了所有内容。我真的希望这会有所帮助。祝一切顺利!API 参考:processing.org/reference/

于 2012-05-25T20:15:42.727 回答