Quantcast
Channel: VBForums - Maths Forum
Viewing all articles
Browse latest Browse all 112

[RESOLVED] Rotating 3d Object by Axis

$
0
0
I'm reworking on an old project 3d GDI+ library and I would like to rotate an object by it's x, y, and z axis'. I'm following this website's instructions on how to do the actual rotating, but I'm running into some issues. When I call my RotateOnZAxis method, it should rotate the object with a 2d feel, but instead it's stretching or shrinking the object. This is my method that I'm using:
Code:

Public Sub RotateOnZAxis(ByVal angle As System.Int32)
    Dim radian As System.Double = angle * Math.PI / 180

    For Each item As Point3d In _vertices
        item.X = Convert.ToInt32(item.X * Math.Cos(radian) - item.Y * Math.Sin(radian))
        item.Y = Convert.ToInt32(item.Y * Math.Cos(radian) - item.X * Math.Sin(radian))
    Next

End Sub

It is basically my conversion of this function:
Code:

var rotateZ3D = function(theta) {
    var sin_t = sin(theta);
    var cos_t = cos(theta);
   
    for (var n=0; n<nodes.length; n++) {
        var node = nodes[n];
        var x = node[0];
        var y = node[1];
        node[0] = x * cos_t - y * sin_t;
        node[1] = y * cos_t + x * sin_t;
    }
};

But instead of having an array of nodes I have an array of vertices where each vertex is a class with an X, Y, and Z property.

The reason I posted this in the math forum is because I believe I'm doing the math wrong; I'm fairly certain that my coding is good, just not my math :/

Viewing all articles
Browse latest Browse all 112

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>