基于两点绘制工字梁

发布于 2024-12-03 04:48:19 字数 310 浏览 2 评论 0原文

我有两个点结构,我需要根据这些点绘制工字梁,其中每个点代表工字梁两侧的横截面。端盖的宽度应是固定且任意的。

基本上我需要画三条线。首先,我将 DrawLine(Point1, Point2),然后我需要数学来弄清楚如何以垂直角度绘制接下来的两条线,以便它们以 Point1 和 Point2 为中心。

下图显示了我需要根据中心线绘制的内容。然而,这条线可以是任何角度。连接线的 Point1 和 Point2 可以位于 2D 空间中的任何位置。

工字梁示例

I have two Point structures and I need to draw an I-Beam based on those points, where each point represents the cross-section on either side of the I-Beam. The width of the end caps should be fixed and arbitrary.

Basically I need to draw three lines. First I'll DrawLine(Point1, Point2), then I need the math to figure out how to draw the next two lines on perpendicular angles so that they are centered on Point1 and Point2.

The image below shows what I need to draw based on the center line. However, this line can be at any angle. The Point1 and Point2 that connect the line can be anywhere in a 2D space.

Example of an I-Beam

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

追星践月 2024-12-10 04:48:19

您可以尝试使用 LineCaps:

protected void DrawIBeam(Graphics g, Point fromPoint, Point toPoint)
{
  using (GraphicsPath hPath = new GraphicsPath())
  {
    hPath.AddLine(new Point(-5, 0), new Point(5, 0));
    CustomLineCap myCap = new CustomLineCap(null, hPath);
    myCap.SetStrokeCaps(LineCap.Round, LineCap.Round);
    using (Pen myPen = new Pen(Color.Black, 2))
    {
      myPen.CustomStartCap = myCap;
      myPen.CustomEndCap = myCap;
      g.DrawLine(myPen, fromPoint, toPoint);
    }
  }
}

并调用它:

DrawIBeam(e.Graphics, new Point(10, 10), new Point(60, 60));

在此处输入图像描述

来自 CustomLineCap 类

You can try playing around with LineCaps:

protected void DrawIBeam(Graphics g, Point fromPoint, Point toPoint)
{
  using (GraphicsPath hPath = new GraphicsPath())
  {
    hPath.AddLine(new Point(-5, 0), new Point(5, 0));
    CustomLineCap myCap = new CustomLineCap(null, hPath);
    myCap.SetStrokeCaps(LineCap.Round, LineCap.Round);
    using (Pen myPen = new Pen(Color.Black, 2))
    {
      myPen.CustomStartCap = myCap;
      myPen.CustomEndCap = myCap;
      g.DrawLine(myPen, fromPoint, toPoint);
    }
  }
}

and call it:

DrawIBeam(e.Graphics, new Point(10, 10), new Point(60, 60));

enter image description here

From CustomLineCap Class

傲影 2024-12-10 04:48:19

假设宽度是工字梁 I 部分宽度的一半,首先找到所绘制的第一条线的斜率。

接下来,取斜率的负倒数,并从 Point1 开始在两个方向上绘制一条长度宽度的线。这就是为什么宽度是你想要绘制的宽度的一半。

最后从点 2 开始在两个方向上画一条长宽的线。

这是绘制垂直线的数学公式。

Assuming a width that's half the width of the I part of the I beam, first you find the slope of the first line you drew.

Next, you take the negative inverse of the slope, and draw a line from Point1 of length width in both directions. That's why width is half of the width you want to draw.

Finally you draw a line from Point 2 of length width in both directions.

Here's the mathematical formula for drawing a perpendicular line.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文