Alex
Alex

Reputation: 1

2D vector to 3D vector

I'm trying to make a circle across a plane using sin and cos. While it works all well when its aligned with the x, y, or z axis, I need something more dynamic. Is there any way to transform a 2D vector to a 3D one using a plane normal, or perhaps another solution?

Upvotes: 0

Views: 2802

Answers (2)

FRA32
FRA32

Reputation: 21

So, if I got your question right, you want to draw a circle in 3D space which is not facing one of the axis directly? A way to do so would be to first use a normal 3D vector as center and draw a circle in a 2D manner around it, so it still faces one of the axis(ignoring the third coordinate). To get the circle rotated you need to use rotation matrixes and apply them to the points that generate the circle. the mathematics for this would be:

raw_point = Center + ( cos(angle)|sin(angle) )

          [raw_point.x]   [1][0             ][0              ]   [cos(YRotation)][0][-sin(YRotation)]   [cos(ZRotation)][-sin(ZRotation)][0]
3DPoint = [raw_point.y] * [0][cos(XRotation)][-sin(XRotation)] * [0             ][1][0              ] * [sin(ZRotation)][cos(ZRotation) ][0]
          [raw_point.z]   [0][sin(XRotation)][cos(XRotation) ]   [sin(YRotation)][0][cos(YRotation) ]   [0             ][0              ][1]

(The bracket blocks are matrixes)

If you need further explanation of the way (rotation-)matrixes work look it up on wikipedia. Btw. if you want to use this method in a code language like java you first need to create a class to contain the mathematics of the matrixes. I can tell you these if neccessary, as I had a dimension-based problem too once.

Upvotes: 0

Marc Müller
Marc Müller

Reputation: 717

You might want to check out MathOverflow.

Upvotes: 1

Related Questions