Jump to content
Sign in to follow this  
Paolo

Working with vectors...

Recommended Posts

I'm using vector data type for my studies on a 3D tree generation tool I already published, as a first release, at www.VectorDepot.com, plugins section.

What I need is a function to rotate vectors in 3D space (same as the Rotate3D for 3D objects).

Example:

code:

Function Vec3DRot(v: Vector; XRot, YRot, ZRot: Real):Vector;

[/code]

I do not know if VW10 has something like this on the vector data type function set, I'm using VW9.5 that has a poor set of functions about vectors.

Thank you in advance for help. [smile]

Share this post


Link to post

Paolo,

Can you describe how you want your function to work? In my limited understanding of 3D vector math, I do know that the order of rotations affects the orientation of the result. For example,

rotate X 90?, rotate Y 90?, rotate Z 90?

yields a different result than,

rotate Y 90?, rotate Z 90?, rotate X 90?.

In the case of the VS command, Rotate3D, the axes are rotated in XYZ order.

Raymond

Share this post


Link to post

The order of rotation MUST respect the VW convention of XYZ order and because vectors are substantially 3D points (the vector starts from 0,0,0 and goes to that point), the rotation has to have the origin (0,0,0) as pivot.

Share this post


Link to post

Paolo,

After overthinking the problem a bit, I finally realized it wasn't all that complicated. Here is my distilled version:

code:

function VecRot3D(V :Vector; RotX, RotY, RotZ :Real) :Vector;

{ Rotate a 3D vector by the amount specified in each axis. Rotation is in degrees. }

{ 14 February 2003 - Raymond Mullin }

Var

U :Vector;

procedure PartialRot(var X, Y :Real; Ang :Real);

var

W : Vector;

Begin

W[1] := X;

W[2] := Y;

W[3] := 0;

W := Ang2Vec(Vec2Ang(W)+Ang, Norm(W));

X := W[1];

Y := W[2];

End; { PartialRot }

Begin

U := V;

PartialRot(U[2], U[3], RotX);

PartialRot(U[3], U[1], RotY);

PartialRot(U[1], U[2], RotZ);

VecRot3D := U;

End; { VecRot3D }
[/code]

Best wishes,

Raymond

Share this post


Link to post

Thank you Raymond, I solved the problem also using matrices. Thanks to Dr. Math

http://mathforum.org/dr.math/

Description:

Given a vector and the three rotation angles (on x, y, z), the result is a new vector corresponding to the first vector rotated.

The resulting function is as follows:

code:

  

function Vec3DRot(v1:Vector;xRot,yRot,zRot:real):vector;

var

m : array[1..3,1..3] of real; {matrice of transformation}

c,s : real; {cosine and sine variables}

vt,v2 : vector; {temporary vectors used in calculations}

begin

vt := v1;

{********** X rotation **********}

c := cos(deg2rad(xRot));

s := sin(deg2rad(xRot));

m[1,1] := 1; m[2,1] := 0; m[3,1] := 0;

m[1,2] := 0; m[2,2] := c; m[3,2] :=-s;

m[1,3] := 0; m[2,3] := s; m[3,3] := c;

{rotation}

v2.x := vt.x * m[1,1] + vt.y * m[2,1] + vt.z * m[3,1];

v2.y := vt.x * m[1,2] + vt.y * m[2,2] + vt.z * m[3,2];

v2.z := vt.x * m[1,3] + vt.y * m[2,3] + vt.z * m[3,3];

{************************************}

vt := v2;

{********** Y rotation **********}

c := cos(deg2rad(yRot));

s := sin(deg2rad(yRot));

m[1,1] := c; m[2,1] := 0; m[3,1] := s;

m[1,2] := 0; m[2,2] := 1; m[3,2] := 0;

m[1,3] :=-s; m[2,3] := 0; m[3,3] := c;

{rotation}

v2.x := vt.x * m[1,1] + vt.y * m[2,1] + vt.z * m[3,1];

v2.y := vt.x * m[1,2] + vt.y * m[2,2] + vt.z * m[3,2];

v2.z := vt.x * m[1,3] + vt.y * m[2,3] + vt.z * m[3,3];

{************************************}

vt := v2;

{********** Z rotation **********}

c := cos(deg2rad(zRot));

s := sin(deg2rad(zRot));

m[1,1] := c; m[2,1] :=-s; m[3,1] := 0;

m[1,2] := s; m[2,2] := c; m[3,2] := 0;

m[1,3] := 0; m[2,3] := 0; m[3,3] := 1;

{rotation}

v2.x := vt.x * m[1,1] + vt.y * m[2,1] + vt.z * m[3,1];

v2.y := vt.x * m[1,2] + vt.y * m[2,2] + vt.z * m[3,2];

v2.z := vt.x * m[1,3] + vt.y * m[2,3] + vt.z * m[3,3];

{************************************}

Vec3DRot := v2; {the resulting vector}

end;
[/code]

Share this post


Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

 

7150 Riverwood Drive, Columbia, Maryland 21046, USA   |   Contact Us:   410-290-5114

 

© 2018 Vectorworks, Inc. All Rights Reserved. Vectorworks, Inc. is part of the Nemetschek Group.

×
×
  • Create New...