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

0 Members and 1 Guest are viewing this topic.

zoltan

  • Guest
Moving, Scaling, and Rotating Points
« on: March 04, 2006, 04:44:15 PM »
If I have a list of points, what is the fastest way to translate, rotate or scale them?

Jürg Menzi posted a file with matrix functions a while back.  How do I use these funcitions to apply them to a list of points and return a new list of points?

It's got to run fast, too!

LE

  • Guest
Re: Moving, Scaling, and Rotating Points
« Reply #1 on: March 04, 2006, 05:10:11 PM »
Zoltan;

In my case, I need to know what is the intention of your code, what are you trying to do, do you have some image or graphics that reflect the end result?... etc....

From there, I might be able to help...

I see you are asking for speed [fast].... why you want to use lisp ?

Have fun
« Last Edit: March 04, 2006, 06:01:46 PM by LE »

zoltan

  • Guest
Re: Moving, Scaling, and Rotating Points
« Reply #2 on: March 04, 2006, 06:26:33 PM »
Sure, let me clearify.

I want to draw text to an image tile in a dialog box using the Vector_Image command .  I have lists of points that I have extracted from exploded text which are all of the ASCII characters 1 unit tall at the origin.  Translating the points to create a list of segments for words is easy, but I want to make it also scale and roate the text.

So. I have a list of 2D points....
((0.032 0.0432)
 (0.432 0.3432)
 (0.432 0.4323)
 ...
)

I need three reosonably fast functions such as this:

(TranslatePoints List BasePoint DestinationPoint)

(RotatePoints List BasePoint Angle)

(ScalePoints List BasePoint ScaleFactor)

They will return a new list int the same form which I will feed to the Vector_Image function.  They should be fast enough to translate a few hundred segments without a noticable pause (not BLAZING fast or anything).

I'm writing a generic function for writing text to an image tile or image button.  I have a "font" file which is a list of points for each character and I will ultimate have a function that will write a line of text to an image at a location, size and rotation, using a given font.

(Text_Image Key Point Angle Height String Font Color)

I figure point transformation is prety basic and someone already has a good, fast function to scale and rotate a list of points better than what I could write.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Moving, Scaling, and Rotating Points
« Reply #3 on: March 05, 2006, 12:16:08 PM »
To get you started ..

This is the pointList for the vertex's of the attached shape.

 
Code: [Select]
(setq ptList '((0 0)
               (-100.0 -50.0)
               (-100.0 50.0)
               (50.0 50.0)
               (50.0 150.0)
               (250.0 150.0)
               (250.0 0.0)
               (200.0 0.0)
               (200.0 -50.0)
               (-100.0 -50.0)
              )
)

kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Moving, Scaling, and Rotating Points
« Reply #4 on: March 05, 2006, 12:19:18 PM »
Code: [Select]
(defun MovePoints (PointList MoveBasePoint MoveVector /)
  (mapcar
    '(lambda (pt) (mapcar '+ MoveVector (mapcar '- pt MoveBasePoint)))
    (if (atom (car PointList))
      (list PointList)
      PointList
    )
  )
)


(MovePoints (list 1 1 ) (list 0 0 ) (list 100 -100))
Code: [Select]
((101 -99))

(MovePoints ptList (list 0 0) (list 0 250))
Code: [Select]
((0 250) (-100.0 200.0)
         (-100.0 300.0)
         (50.0 300.0)
         (50.0 400.0)
         (250.0 400.0)
         (250.0 250.0)
         (200.0 250.0)
         (200.0 200.0)
         (-100.0 200.0)
)


(MovePoints ptList (list 0 0) (list 1000 -1000))
Code: [Select]
((1000 -1000) (900.0 -1050.0)
              (900.0 -950.0)
              (1050.0 -950.0)
              (1050.0 -850.0)
              (1250.0 -850.0)
              (1250.0 -1000.0)
              (1200.0 -1000.0)
              (1200.0 -1050.0)
              (900.0 -1050.0)
)
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Moving, Scaling, and Rotating Points
« Reply #5 on: March 05, 2006, 12:27:44 PM »
Code: [Select]
(defun scalePoints (PointList ScaleBasePoint ScaleFactor / ScaleList)
  (setq ScaleList (list ScaleFactor ScaleFactor ScaleFactor))
  (mapcar '(lambda (pt)
             (mapcar '+
                     ScaleBasePoint
                     (mapcar '* ScaleList (mapcar '- pt ScaleBasePoint))
             )
           )
          (if (atom (car PointList))
            (list PointList)
            PointList
          )
  )
)

( scalePoints (list 10 20) (list 0 0) 3.52)
Code: [Select]
((35.2 70.4))
( scalePoints ptList (list 0 0) 0.5)
Code: [Select]
((0.0 0.0) (-50.0 -25.0)
           (-50.0 25.0)
           (25.0 25.0)
           (25.0 75.0)
           (125.0 75.0)
           (125.0 0.0)
           (100.0 0.0)
           (100.0 -25.0)
           (-50.0 -25.0)
)

( scalePoints ptList (list -100 -50 ) 2.0)
Code: [Select]
((100.0 50.0) (-100.0 -50.0)
              (-100.0 150.0)
              (200.0 150.0)
              (200.0 350.0)
              (600.0 350.0)
              (600.0 50.0)
              (500.0 50.0)
              (500.0 -50.0)
              (-100.0 -50.0)
)

I'm going out, so the Rotate will have to wait.
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
Re: Moving, Scaling, and Rotating Points
« Reply #6 on: March 05, 2006, 01:01:34 PM »
Good stuff Kerry.
TheSwamp.org  (serving the CAD community since 2003)

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Moving, Scaling, and Rotating Points
« Reply #7 on: March 05, 2006, 01:16:46 PM »
Thanks Mark, but I stand on the shoulders of Giants. :-)

BTW , those should work for 3D points as well ..
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Moving, Scaling, and Rotating Points
« Reply #8 on: March 05, 2006, 01:53:40 PM »
Zoltan,

As you have Jürg's Matrix Library [ I can't get it till the Lilly_Pond plumbing is fixed ] ,

Have a look at this for the Rotation ..
http://www.theswamp.org/index.php?topic=8251.msg105994#msg105994
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

GDF

  • Water Moccasin
  • Posts: 2081
Re: Moving, Scaling, and Rotating Points
« Reply #9 on: March 05, 2006, 02:37:43 PM »
That would be sweet indeed...

Quote
...
I want to draw text to an image tile in a dialog box using the Vector_Image command .  I have lists of points that I have extracted from exploded text which are all of the ASCII characters 1 unit tall at the origin.  Translating the points to create a list of segments for words is easy, but I want to make it also scale and roate the text.
...
I'm writing a generic function for writing text to an image tile or image button.  I have a "font" file which is a list of points for each character and I will ultimate have a function that will write a line of text to an image at a location, size and rotation, using a given font.
...

Have you checked out Terry Miller's vector_line creation function?

Code: [Select]
From Terry's routine:
;-------------------------------------------------------------------------------
; Program Name: GetVectors.lsp [GetVectors R3]
; Created By:   Terry Miller (Email: terrycadd@yahoo.com)
;               (URL: http://web2.airmail.net/terrycad)
; Date Created: 12-7-01
; Function:     c:GetVectors explodes selected entities into lines segments and
;               writes vector points to C:\Temp\Vectors.lsp which may be viewed
;               by c:ViewVectors.
; Note: There are a few informative notes at the end of this file.
;-------------------------------------------------------------------------------
; Revision History
; Rev  By     Date    Description
;-------------------------------------------------------------------------------
; 1    TM   12-7-01   Initial version
; 2    TM   5-20-04   Added dialogs to assist in creating dialog images.
; 3    TM   3-20-05   Added c:Palet function to view AutoCAD's 255 colors.
;-------------------------------------------------------------------------------
; GetVectors is a programming tool for creating dialog images from AutoCAD
; entities. The entities selected will be exploded into line segments to create
; the image and dialog files C:\Temp\Vectors.lsp and C:\Temp\Vectors.dcl.
; Use the function ViewVectors to view the images created by GetVectors. The
; image and dialog files created by GetVectors may be pasted into your own
; programs and modified as needed.
;-------------------------------------------------------------------------------
; Instructions: Draw a rectangle in units corresponding to the pixel units of
; the image you want to create. For example to create a 50 x 50 pixel image,
; draw a rectangle from 0,0 to 49,-49. Copy and scale the entities you want to
; include in your image into the limits of the outlined rectangle. GetVectors
; creates the blocks GetVectors and DupVectors for reference. Move the blocks
; or the entities off to the side and make modifications as needed.
;-------------------------------------------------------------------------------
; Overview of Main Functions
;-------------------------------------------------------------------------------
; c:GetVectors - Creates an image and dialog file of entities selected.
; c:GV - Shortcut for c:GetVectors
; GetVectors - Function called by c:GetVectors that explodes selected entities
;    into lines segments and writes vector points to C:\Temp\Vectors.lsp.
; WmfExplode - Function called by GetVectors that creates a WMF file of the
;    selection and then explodes the WMF entities into lines.
; c:ViewVectors - View vectors created by c:GetVectors in C:\Temp\Vectors.lsp.
; c:VV - Shortcut for c:ViewVectors
; c:ImageAtts - Image Attributes dialog used to calculate the height and width
;    of dialog images.
; c:IA - Shortcut for c:ImageAtts
; c:Palet - Displays a Palet Image to view AutoCAD's 256 colors.
; c:PI - Shortcut for c:Palet
;-------------------------------------------------------------------------------
; c:GetVectors - Creates an image and dialog file of entities selected.
;-------------------------------------------------------------------------------


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 #10 on: March 05, 2006, 11:02:55 PM »
Kerry, Thanks alot for saving me lots of work.  That function by Jurg was exactly what I was looking for.  Thanks! I knew I had seen it somewhere.

Gary, That is the function which gave me the idea.  I made a loop that put each of the 255 ASCII characters to the origin one at a time using the current shx font and I a method similar to Terry's routine to explode the text to lines.  Then I collected the end points to create the "font" file which I will now scale and rotate with a little help from Kerry and Jurg.

I will post it up here Tomorrow or the next day.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Moving, Scaling, and Rotating Points
« Reply #11 on: March 06, 2006, 12:20:50 AM »
My pleasure.

I know you'll reciprocate :-)
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

GDF

  • Water Moccasin
  • Posts: 2081
Re: Moving, Scaling, and Rotating Points
« Reply #12 on: March 06, 2006, 11:54:57 AM »
Quote
I will post it up here Tomorrow or the next day.

Can't wait to see it...

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 #13 on: March 08, 2006, 08:46:53 AM »
Ok..Between doing what I'm supposed to be doing and sleeping I got this somewhat together.  It still needs work, though.

The insertion point and rotation are completely out to lunch! I have not had the time to look into it.
Also, I can't get it to draw vectors before or after the text.  They just don't show up!!  I had originally intended to do it like this:
(Start_Image ... )
(Fill_Image ... )
(Text_Image ... )
(End_Image )

This did not work.  It would not draw any vectors.  So I had to put Start_Image and End_Image in the loop and start and end the image for every vector.  Now I can't add more vector before of after the Text_Image function.
This is not good.  In application, it will have to work with other vector_Image calls and multiple calls to Text_Image.
So I'm stumped on this one.

The Progy to make the fonts Text2Vec is a little funny.  I originally did the lazy thing and turned the Express Tools command Explode Text into a function that I gave a selection set to.  It was slow, but it worked.  Later I refined it by taking code from Terry Miller's GetVectors.lsp to make it faster, but it might be a little flacky based on looking at the commands calls fly by.  You can comment out my txtexp function and uncomment the whole express one and see the difference.

You can use the TestVecs progy to test the font.

*****CHANGE THE PATH IN THE C:TESTTEXT OR IT WON'T WORK!!!!!!!!!
(SetQ sPath "E:\\Programming\\Lisp\\Text2Vec\\" )

zoltan

  • Guest
Re: Moving, Scaling, and Rotating Points
« Reply #14 on: March 08, 2006, 11:18:07 PM »
OK,  A couple of revisions since this morning.  I found out that calling Get_Tile or Set_Tile in between the Start_Image and End_Image calls really messes things up. so I revised the Draw_Text function to look like this:
Code: [Select]
(Defun Draw_Text ( / xmax ymax posx posy rot height text space vecs)
 (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
            )
           )
 )

 (End_Image )
 (Set_Tile "vectors" vecs )
)
now that works... so also take out the Start_Image and End_Image calls in the Text_Image loop.

I determined that the messed up text insertion point and rotation base point was caused by the MeRotatePointList function.  Unless Jürg gives me some insite about how I'm using his function wrong, I will have to dig through it and try to understand it, or re-write it entirelly.  (let's hope Jürg jumps into this thread soon!).

  Other than that everything is groovy.  The Text2Vec program seems to work, it just does not give any visual indication that it's doing anything.  That's always fun!