Search code examples
c#wpfwindows3dhelix-3d-toolkit

C# Helix Toolkit how to draw a rectangular prism between points?


I'm trying to draw a shape between two points (represented as Point3D objects).

The goal is to create a path/road from point A to B as a rectangular prism, so it would be flat and short on the sides (e.g. a length of 10, a width of 3, and a height of 1, with the ends of the shape at each point).

So far, I've tried creating a box shape using Helix Toolkit's built-in helper methods, using the midpoint between the points as the center:

AddBox(Point3D center, Vector3D x, Vector3D y, double xlength, double ylength, double zlength, BoxFaces faces = BoxFaces.All)

The problem is I don't understand if or how I can control the rotation and angle of the box so that it will connect the two points if they are diagonal from each other or at different heights.

Is there a way to achieve this more elegantly? Maybe something more like the AddTube method which supplies points as a path?:

AddTube(IList<Point3D> path, double diameter, int thetaDiv, bool isTubeClosed)

Thanks


Solution

  • So I managed to find the following solution here.

    Essentially, I just refitted the code at that link to do what I needed to do. I adjusted the scale factor for thickness and width, as well as made an enum that I can switch on to set the prism's direction:

    Vector3D dir = new Vector3D();
    switch (faceDirection)
    {
        case VectorUpFace.Up:
            dir = new Vector3D(0, 0, 1);
            break;
        case VectorUpFace.Left:
            dir = new Vector3D(0, -1, 0);
            break;
         case VectorUpFace.Right:
            dir = new Vector3D(0, 1, 0);
            break;
         case VectorUpFace.Front:
            dir = new Vector3D(1, 0, 0);
            break;
     }
    

    Then, the dir vector is used in the call to ScaleVector (see the link at the beginning of this answer).