To LUGNET HomepageTo LUGNET News HomepageTo LUGNET Guide Homepage
 Help on Searching
 
Post new message to lugnet.cad.devOpen lugnet.cad.dev in your NNTP NewsreaderTo LUGNET News Traffic PageSign In (Members)
 CAD / Development / 7032
7031  |  7033
Subject: 
Re: Help wanted from the programmers among the LUGNET group
Newsgroups: 
lugnet.cad.dev
Date: 
Tue, 5 Mar 2002 20:10:28 GMT
Viewed: 
355 times
  
In lugnet.cad.dev, Ludo Soete writes:
Hello,

Is there someone among the programmers, who can deliver me the algorithm for
the ROTATION of the five different line types ?
Please in some understandable language, so that i can translate it into
VB(A) code - NO ASSEMBLER CODE.

LDraw AddOn does rotations in at least a couple of different places.  In
class file EditorFunctions.cls, there's the Rotate() method and the
QuickRotate() method, both of which are capable of rotating any LDraw code
around any of the three axes.

Also, in module LDrawUtils.bas, function LDL2DAT converts a block of LDLite
code to standard LDraw code.  This includes translating the ROTATE
meta-statement, which can rotate LDraw code around any vector.

You can get the source code for LDraw AddOn from
http://www.geocities.com/partsref/ldao/source.html

Unfortunately, none of the routines I mentioned are really a good example -
they've got too much else going on to really show what's up with the
rotating. :)

In more general terms, you need to multiply every 3D point in the LDraw
commands by a rotation matrix (good news: you can treat the 9 transform
parameters in the type 1 lines as 3 3D points).

So do the following:
1. Build a transform matrix A().  Constructing A() by hand isn't too hard,
especially if you are rotating around X, Y, or Z.

To rotate around the Y axis by angle Q, A() would be:

cos Q  0  -sin Q
  0    1     0
sin Q  0   cos Q

Then, you just have to process each command line, multiplying each xyz
triple by A().  The whole thing would look something like this (warning: I'm
writing this off the cuff, and I'm notoriously bad at getting this stuff
right the first time; in particular, matrix subscripts may be switched).

Sub MatrixMultiply(P1() As Double, A() As Double, P2() As Double)
' Multiply a 1x3 array by a 3x3 array to give a 1x3 array
   Dim i As Long, j As Long

   For i = 0 to 2
      For j = 0 to 2
         P2(i) = P2(i) + P1(j) * A(i, j)
      Next j
   Next i
End Sub

Function RotateY(ByVal sLDrawCode As String, ByVal Q as Double) As String
   Dim A(2,2) As Double
   Dim P1(2) As Double
   Dim P2(2) As Double
   Dim sLine() As String
   Dim sParam() As String
   Dim i As Long
   Dim j As Long

   A(0, 0) = Cos(Q) : A(1, 0) = 0 : A(2, 0) = -Sin(Q)
   A(0, 1) = 0      : A(1, 1) = 1 : A(2, 1) = 0
   A(0, 2) = Sin(Q) : A(1, 2) = 0 : A(2, 2) = Cos(Q)

   sLine = Split(sLDrawCode, vbCrLf)
   For i = 0 to Ubound(sLine)
      sParam = Split(sLine(i), " ") ' Probably too simplistic
      If Instr("12345", sParam(0)) <> 0 Then
         For j = 2 To Ubound(sParam) - 1 Step 3
            P1(0) = sParam(j): P1(1) = sParam(j + 1): P1(2) = sParam(j + 2)
            MatrixMultiply P1, A, P2
            sParam(j) = P2(0): sParam(j + 1) = P2(1): sParam(j + 2) = P2(2)
         Next j
      End If
      sLine(i) = Join(sParam, " ")
   Next i

   RotateY = Join(sLine, vbCrLf)
End Function

Why i'm asking for?
I'm working on a part witch can be split-up into different parts, for ease
of creation. Each part need to be copied and rotated by 90°,180° & 270° to
get the complete part. Some of those 'sub' parts are over 100 ... 200 lines
long.

You *could* just use LDLite commands to control the rotation, then use LDAO
to translate the final code to straight LDraw.

Or use LDAO to rotate the lines.

Steve



Message is in Reply To:
  Help wanted from the programmers among the LUGNET group
 
Hello, Is there someone among the programmers, who can deliver me the algorithm for the ROTATION of the five different line types ? Please in some understandable language, so that i can translate it into VB(A) code - NO ASSEMBLER CODE. Why i'm (...) (23 years ago, 5-Mar-02, to lugnet.cad.dev)

4 Messages in This Thread:



Entire Thread on One Page:
Nested:  All | Brief | Compact | Dots
Linear:  All | Brief | Compact
    

Custom Search

©2005 LUGNET. All rights reserved. - hosted by steinbruch.info GbR