Author Topic: Moving, Scaling, and Rotating Points  (Read 10374 times)

0 Members and 2 Guests are viewing this topic.

GDF

  • Water Moccasin
  • Posts: 2081
Re: Moving, Scaling, and Rotating Points
« Reply #15 on: March 09, 2006, 10:19:30 AM »
zoltan

Don't forget to clear your vector line image....so that when you select another font within your dialog box you don't get images on top of one another.


Gary
« Last Edit: March 10, 2006, 10:54:56 AM by Gary Fowler »
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

GDF

  • Water Moccasin
  • Posts: 2081
Re: Moving, Scaling, and Rotating Points
« Reply #16 on: March 10, 2006, 10:53:45 AM »
zoltan

Quote
Don't forget to clear your vector line image....so that when you select another font within your dialog box you don't get images on top of one another.

This is a quick update to your routine, so that it will reset the dialog box image.

Code: [Select]
(defun ResetTextImage  ()
  (SetQ xmax   (DimX_Tile "textimage")
        ymax   (DimY_Tile "textimage")
        posx   (DistoF (Get_Tile "posx"))
        posy   (DistoF (Get_Tile "posy"))
        rot    (AngtoF (Get_Tile "rot"))
        height (DistoF (Get_Tile "height"))
        text   (Get_Tile "text")
        space  (DistoF (Get_Tile "space")))
  (Start_Image "textimage")
  (Vector_Image 0 (Fix posy) xmax (Fix posy) 1)
  (Vector_Image (Fix posx) 0 (Fix posx) ymax 1)
  (fill_image 0 0 xmax ymax -2)
  (End_Image))

(Defun Draw_Text  (/ xmax ymax posx posy rot height text space vecs)
  (ResetTextImage)
  (SetQ xmax   (DimX_Tile "textimage")
        ymax   (DimY_Tile "textimage")
        posx   (DistoF (Get_Tile "posx"))
        posy   (DistoF (Get_Tile "posy"))
        rot    (AngtoF (Get_Tile "rot"))
        height (DistoF (Get_Tile "height"))
        text   (Get_Tile "text")
        space  (DistoF (Get_Tile "space")))
  (Start_Image "textimage")
  (fill_image 0 0 xmax ymax -2)
  (Vector_Image 0 (Fix posy) xmax (Fix posy) 1)
  (Vector_Image (Fix posx) 0 (Fix posx) ymax 1)
  (SetQ vecs (ItoA (Text_Image posx posy rot height text lstCurrentFont space 2))) ;set color
  (End_Image)
  (Set_Tile "vectors" vecs))

Gary
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

zoltan

  • Guest
Re: Moving, Scaling, and Rotating Points
« Reply #17 on: March 10, 2006, 06:38:26 PM »
I'm confused here, Gary.  You are calling
Code: [Select]
(Vector_Image 0 (Fix posy) xmax (Fix posy) 1)
(Vector_Image (Fix posx) 0 (Fix posx) ymax 1)
(fill_image 0 0 xmax ymax -2)
in the ResetTextImage subroutine to clear the image and draw the crosshairs for the insertion point and then you are calling them again in the DrawText subroutine.  But I would agree with you that clearing the image should be a seperate subroutine that can be called at any time.

Keep in mind that this whole program is just to test the function of the Text_Image function.

By the way, where the heck is Jürg to help me out with his MeRotatePointList function?!?!

Jürg Menzi

  • Swamp Rat
  • Posts: 599
  • Oberegg, Switzerland
Re: Moving, Scaling, and Rotating Points
« Reply #18 on: March 11, 2006, 05:43:19 AM »
By the way, where the heck is Jürg to help me out with his MeRotatePointList function?!?!
Zoltan, I can't scan all messages during my work time. In this case send me a PM to get my attention... :-)

All right, what's the problem with MeRotatePointList?

Cheers

A computer's human touch is its unscrupulousness!
MENZI ENGINEERING GmbH
Current A2k16... A2k24 - Start R2.18

zoltan

  • Guest
Re: Moving, Scaling, and Rotating Points
« Reply #19 on: March 11, 2006, 08:48:18 AM »
Jürg

Thank you so much for helping me out.

I don't know if I have implemented your function correctly.  If you read through this thread, I have created a function to write text to an image tile in lisp using a "font" which is a list of start point - end point pairs for each ascii character.  The lists are concatenated to form a string of text that is given to a loop which feeds it to a Vector_Image call to draw them to the tile.  All of the characters in the font file are stored at 0,0 with a rotation of 0 and a height of 1.  When the text string is built, the first list of points is moved to the insertion point of the text and the other characters are translated to the right by a distance given by the characters with plus the space between the characters.  This is done with Kerry Brown's MovePoints function.

Then the entire list of points for the text string is scaled about the insertion point to get the desired text height and then rotated around the insertion point by the rotation angle before it is looped to the Vector_Image function.

I has re-attached the zip file with the latest changes.  Load the files and run the C:TestText prog.  The red lines are the insertion point of the text.  When the MeRotatePointList function call to rotate the text is not commented out, the text is translated away from the insertion point.  The rotation angle is correct (albeit backwards since the stupid image tile coordinate system is upside-down!), but the base point is moved.


Jürg Menzi

  • Swamp Rat
  • Posts: 599
  • Oberegg, Switzerland
Re: Moving, Scaling, and Rotating Points
« Reply #20 on: March 11, 2006, 09:33:03 AM »
Zoltan

I will check that out... sunday or moday.
A computer's human touch is its unscrupulousness!
MENZI ENGINEERING GmbH
Current A2k16... A2k24 - Start R2.18

Jürg Menzi

  • Swamp Rat
  • Posts: 599
  • Oberegg, Switzerland
Re: Moving, Scaling, and Rotating Points
« Reply #21 on: March 13, 2006, 12:57:56 PM »
Zoltan

Couldn't check all details, but I've seen that the vector list has an offset to the rotation point,
means there is no point in the list at ~0,0,0...
A computer's human touch is its unscrupulousness!
MENZI ENGINEERING GmbH
Current A2k16... A2k24 - Start R2.18

zoltan

  • Guest
Re: Moving, Scaling, and Rotating Points
« Reply #22 on: March 13, 2006, 03:29:16 PM »
Yes, that is exactly what is going on.  Even with the rotation angle set to 0, the vectors are all away from the origin point.  If you comment out the line that processes the rotation, you will see that the text will be on the red cross-hairs that mark the insertion point.

zoltan

  • Guest
Re: Moving, Scaling, and Rotating Points
« Reply #23 on: March 13, 2006, 07:17:07 PM »
Ok... I managed to somehow sort out the issue by changing around the logic of the insertion point.

I added a Justification parameter and fixed some isses with empty strings and leading spaces.  Give it a run and see if anything is wrong, particularly the application of the justification. 

Also, if anyone would like to try to come up with ways of making it faster, I would love to hear about it.  In practical application, small text on the image tile looks fine using RomanS or RomanD. They run fast enough and look good at small text height.  It gets a little slow when using TrueType fonts since they produce so many line segments.  I'm sure with a little streamlining, we could make it very practical for writing larg paragraphs of TrueType to the image.

Jürg Menzi

  • Swamp Rat
  • Posts: 599
  • Oberegg, Switzerland
Re: Moving, Scaling, and Rotating Points
« Reply #24 on: March 14, 2006, 03:01:24 AM »
Hi Zoltan

The main reason for slow down your function is the sub 'Text_Image'. Independent of the parameter you're change
in the dialog, the sub executes *all* calculations. You should split the calc's to the necessary behaviour, eg.:
- Change rotation angle -> calculate rotation -> draw vec's
- Change height -> calculate scale -> draw vec's
etc.

Another hint (has no big influence to speed), my matrix functions can be used to scale and move also:
Code: [Select]
;
; == Function MeScalePointList
; Scales a point list referring to the base point by a factor.
; Copyright:
;   ©2001 MENZI ENGINEERING GmbH, Switzerland
; Arguments [Type]:
;   Ptl = Point list [LIST]
;   Bpt = Base point [LIST]
;   Scl = Scale factor [REAL]
; Return [Type]:
;   Point list [LIST]
; Notes:
;   - None
;
(defun MeScalePointList (Ptl Bpt Scl / MatOcs)
 (setq MatOcs (MeMatScale Scl Bpt))
 (mapcar '(lambda (l) (MeTrans l MatOcs)) Ptl)
)
;
; == Function MeMovePointList
; Moves a point list referring to the base point by displacement.
; Copyright:
;   ©2001 MENZI ENGINEERING GmbH, Switzerland
; Arguments [Type]:
;   Ptl = Point list [LIST]
;   Bpt = Base point [LIST]
;   Dpt = Displacement point [LIST]
; Return [Type]:
;   Point list [LIST]
; Notes:
;   - None
;
(defun MeMovePointList (Ptl Bpt Dpt / MatDsp MatOcs)
 (setq MatOcs (MeMatRotZ (angle Bpt Dpt) '(0.0 0.0 0.0))
       MatDsp (MeTrans (list (distance Bpt Dpt) 0.0 0.0) MatOcs)
 )
 (mapcar '(lambda (l) (MeVecAdd l MatDsp)) Ptl)
)

A computer's human touch is its unscrupulousness!
MENZI ENGINEERING GmbH
Current A2k16... A2k24 - Start R2.18

zoltan

  • Guest
Re: Moving, Scaling, and Rotating Points
« Reply #25 on: March 14, 2006, 07:18:25 AM »
Jürg,

While it is true that the Text_Image function has to create and process a new list of vectors every time, the purpose of this exercise is not the application "Test Test".  The Test Test is just a test function to debug the Text_Image function which is intended to stand alone and be used in any application to write text to any image tile in any dialog box.

To make the performance change you are talking about would require the main application to store the list of vectors along with all of the parameters to determine what changed and then process the same list of vectors.  This would only increase the speed of subsequent changes to the same vector list.  While this is applicable to my test function, in normal application one would typically not write text to a image and than change just the rotation of the same text unless they were trying to create some kind of animated effect.  Normally, the Text_Image function would be called to write a string to an image and then called again to write another string to the same or another image.

One performance increase that I could do is not calculate the rotation if it is set to 0, which will be most cases.

Thank you for your input, Jürg.