HP Forums
Rotate text? - Printable Version

+- HP Forums (https://www.hpmuseum.org/forum)
+-- Forum: HP Calculators (and very old HP Computers) (/forum-3.html)
+--- Forum: HP Prime (/forum-5.html)
+--- Thread: Rotate text? (/thread-2938.html)



Rotate text? - DrD - 01-26-2015 03:28 PM

I want to rotate text placed just outside the circumference of a circle, in order to label radials. I would appreciate some help on how this might be accomplished. Can TEXTOUT_P(), or PIXON_P() be used to rotate text in some fashion?

Thanks,

-Dale-


RE: Rotate text? - cyrille de brébisson - 01-27-2015 06:57 AM

Hello,

Unfortunately no.

there is no rotate function in Prime, sorry.
If you want a rotation, you will need to draw your text on a transparent bitmap (G1), and then create a rotation function and then blit the result..


What are you working on?

Cyrille


RE: Rotate text? - Damien - 01-27-2015 07:22 AM

Something like that may help you ?
(angles are in radian)
Code:

EXPORT ROT()
BEGIN 
 LOCAL sa,ca,a,x,y;
 DIMGROB(G1,40,40);
 RECT_P(99,79,140,120,0,RGB(255,255,255));
 FOR a:=0 to 2*π STEP π/15 DO
  RECT_P(G1);
  sa:=-SIN(a); ca:=COS(a);
  FOR x=-20 TO 20 DO
   FOR y=-20 TO 20 DO
    PIXON_P(G1,x+20,y+20,GETPIX_P(G0,x*ca-y*sa+20,x*sa+y*ca+20);
   END;
  END;
  BLIT_P(G0,100,80,140,120,G1,0,0,40,40);
 END;
 WAIT(1);
END;

I hope it will work, i haven't got the prime with me to verify.

Regards,

Damien


RE: Rotate text? - cyrille de brébisson - 01-27-2015 09:11 AM

Hello,

Sorry that we did not have time to create a textured triangle drawing function. It would have solved that issue...

cyrille


RE: Rotate text? - DrD - 01-27-2015 11:20 AM

I have created a Smith chart grob, and want to circumscribe wavelengths to/from, load/generator, around the perimeter of the chart. I use most of the graphics screen for the chart itself, in order to make it most readable. Thus, if I could wrap wavelength labeling around the circle, it would be desirable.

I've thought about rotating each character (bit by bit), but was in hopes that there was an inbuilt way to do text rotation that I hadn't yet discovered.

Thank you for your suggestions.

-Dale-


RE: Rotate text? - Thomas_Sch - 01-27-2015 12:05 PM

(01-27-2015 11:20 AM)DrD Wrote:  I have created a Smith chart grob, and want to circumscribe wavelengths to/from, load/generator, around the perimeter of the chart. I use most of the graphics screen for the chart itself, in order to make it most readable. Thus, if I could wrap wavelength labeling around the circle, it would be desirable.

I've thought about rotating each character (bit by bit), but was in hopes that there was an inbuilt way to do text rotation that I hadn't yet discovered.

Thank you for your suggestions.

-Dale-

Hello Dale,
Do you plan to publish your program? In my opinion, there are many interested ..

Thomas


RE: Rotate text? - DrD - 01-27-2015 01:27 PM

I have a few objectives that I want to accomplish, most of which are functional now. If successful, I will look over my code for 'improvements', and write up a brief explanation of the features I've captured, along with related usage examples. No problem with sharing it, but it's not quite presentable yet.

I started with an impedance Smith chart, plotting complex impedance values based on normalized gamma or load impedance. I also wanted to plot matching networks using capacitive, inductive, or transmission line lengths, as needed, to result in 1:1 VSWR, (zero reflection coefficient). I'm sort of stuck at this point, since I want to easily view transmission line length on the chart, hence the need for perimeter wavelength labeling, i.e., rotated text!

In the meantime, I've added the inverse impedance chart, for admittance. Thus facilitating series OR parallel matching networks, so much the better. (The so-called "immitance" Smith chart).

Trying to get this coded sure makes me appreciate Mr. Smith, and all of his work in creating the original chart design! I began this adventure using a Python program approach. As the program evolved, it seemed like I could do this with the Prime, also. If ever we can communicate with the outside world to a remote terminal unit, it could be useful as a very handy, compact, VNA, (vector network analyzer), for antenna work and such.

Most likely, it will just end up as another of those 'things' I do, towards some uncertain end ...

-Dale-


RE: Rotate text? - Thomas_Sch - 01-27-2015 08:27 PM

Hello Dale,
Many thanks for your detailed explanations.
That sounds like a very, very challenging project.
I didn't know the different variants of the Smith chart in detail.
(The degree in electrical engineering is long gone.)

I wish you much persistence and success!

Thomas


RE: Rotate text? - DrD - 02-03-2015 03:34 PM

Below is a condensed program that has resulted from my attempt to rotate text around the circumference of a circle. I would like to solicit ideas for making the speed of the subroutine, (containing the x and y loops), faster. On the hardware device, the program is taking just over 6 seconds to complete, currently.

The program works by placing twelve known 30° data points in a word list. Each data point is placed at the G1 origin, and passed to the subroutine, whereby each pixel in that string gets analyzed, its location on the circle determined (in the x,y loops), and affixed to G1; then when all is ready, transferred to GO for final display.

The x-y subroutine is slower than molasses in winter. The prime chokes, until it eventually coughs up the display. After trying several things that are slower yet, I wonder if there are still better, faster ways to accomplish this? If you patiently wait out the six-seven seconds watching a beautiful blank screen, this program should reward you with the graphic of my efforts, thus far.

Help is both needed and appreciated! This project is for fun(?) only, with no commercial intentions. You can see the run-time from Home. Enter: time(Atest); once the display shows up, push the HOME button. I'm seeing around 6.05 seconds.

Thanks!

-Dale-

Drum roll ...

Code:

wrt();
EXPORT Atest()
BEGIN 

LOCAL a,b,j,ang, sa,ca;
LOCAL word;                  // local var rot was used to rotate legends 90° to circle

HAngle:=0;    // Radians mode
// rot:=pi/2;    // Rotate 90° for legends

//  Word{list} pre-calculated legend parameters: {"Deg", ca, sa, a, b} is (12,5), 60 elements
//  ca:=COS(ang-rot); sa:=SIN(ang-rot);     Text rotation angle
word:={
             "0.0°",0,-1,269,102,
             "30°",0.5,-0.87,251,46,
             "60°",0.87,-0.5,208,7,
             "90°",1.0,0,150,0,
             "120°",0.87,0.5,90,15,
             "150°",0.5,0.87,53,59,
             "180°",0,1,43,118,
             "-150°",-0.5,0.87,64,178,
             "-120°",-0.87,0.5,111,215,
             "-90°",-1,0,169,219,
             "-60°",-0.87,-0.5,224,201,
             "-30°",-0.5,-0.87,260,156
              }; 

DIMGROB(G1,320,240);  // G1 workspace
RECT_P();                     // Clear screen 

ang:=0;    //  Initial starting angle 
FOR j FROM 1 to 60 STEP 5  do
  
   TEXTOUT_P(word(j),G1,0,0,1);     // Temporary workspacet G1 origin (0,0)

   ca:=word(j+1);
   sa:=word(j+2);
   a:=word(j+3);
   b:=word(j+4);
   wrt(ca,sa,a,b);   //  Compute legend location on screen 
   LINE_P(G1,156,109,105*COS(ang)+156,105*-SIN(ang)+109,RGB(255,0,0));  //  30° spokes in circle
   RECT_P(G1,0,0,30,24);    // Clear textout temporary workspace on G1

   ang:=ang+pi/6;   //  Increment angle 30°
      
END;     //  For ang 30° step

ARC_P(G1,156,109,105,RGB(255,0,0));   //  Draw outer circle
BLIT_P(G0,G1);                                     //  Draw legend on screen 
DRAWMENU("","","","","","");                  //  Add Softmenu keys

freeze;  // Pause for viewing

END;     // Atest()

// =============================< Subroutines >=======================================

wrt(ca,sa,a,b)
BEGIN
LOCAL x,y;

//  String is (24 pixels W x 10 pixels H), occuping ±25 pixels total when rotated.  Circle: 210 pixel diameter, 105 pixel radius, center at  (156, 109) 
FOR x:=-25 TO 25 DO
        
  FOR y:=-25 TO 25 DO

    PIXON_P(G1,x+a,y+b,GETPIX_P(G1,x*ca-y*sa,x*sa+y*ca));    //  Places legend at (x,y), rotated by ang-pi/2
         
  END;  // end y-height pixels      

END;   // end x-width pixels    

END;



RE: Rotate text? - cyrille de brébisson - 02-04-2015 07:41 AM

Hello


FOR x:=-25 TO 25 DO
FOR y:=-25 TO 25 DO
PIXON_P(G1,x+a,y+b,GETPIX_P(G1,x*ca-y*sa,x*sa+y*ca));
END; // end y-height pixels
END; // end x-width pixels

They are 2 types of items that you can control here:
- 2 loops
- 4 parameter calculations

you need the loops and you can not transform the using matrices or the like, so nothing to improve there.

You can however do something on the parameter calculations.

you have the x+a and y+b. These could be speed up by using binary numbers rather than floats but the cost of doing the conversion would be higher than the cost of doing the floating point calculations. So there is no point in looking further there.

you then have the GETPIX_P pixel calculations. there is quite a lot there, 4 multiplications and 2 additions (well substractions)... This, you can improve on!
create a local variable where you place your rotation as a complex number (rot) and then do GETPIX_P(G1,(x,y)*rot) and let the system do the * and - internally which will be faster because there is no memory allocations for results and time spent in executing your code.

This is prety much all that I can think of.

cyrille


RE: Rotate text? - Han - 02-04-2015 01:18 PM

Build your alphabet as a set of skeletal points. Make a function that builds a point list from the alphabet and modifies the points to translate by (a,b). A makelist() call would be very fast for this. Finally use the line_p() command with a rotation matrix to draw the lines forming your word.

Also just using makelist() in place of for loops will speed things up a tad.


RE: Rotate text? - DrD - 02-04-2015 01:25 PM

(02-04-2015 07:41 AM)cyrille de brébisson Wrote:  FOR x:=-25 TO 25 DO
FOR y:=-25 TO 25 DO
PIXON_P(G1,x+a,y+b,GETPIX_P(G1,x*ca-y*sa,x*sa+y*ca));
END; // end y-height pixels
END; // end x-width pixels

"create a local variable where you place your rotation as a complex number (rot) and then do GETPIX_P(G1,(x,y)*rot)"

cyrille

Thank you for your idea! It should help, but the output format of, "(x,y)*rot" doesn't seem to be compatible with the GETPIX_P[(G],x,y) function. The output is of the form "(x,y)" and the additional overhead to break x and y out of the parens, negates any speed gain.

It's possible I'm not doing something quite right according to your plan, though. If convenient, could you elaborate a bit?

Thanks!

-Dale-


RE: Rotate text? - DrD - 02-04-2015 01:50 PM

(02-04-2015 01:18 PM)Han Wrote:  Build your alphabet as a set of skeletal points...

That was an idea I had thought of, as well. After a few attempts, I kind of got lost in the devilish details, and abandoned the effort. I thought that since I only needed a few characters, I would build a matrix for them, and dissect the matrix in the loops. That was not one of my better ideas!

Ultimately, this is a circular reference set of points for the Smith chart project I've been fiddling with. As far as the chart is concerned, it's just a handy reference. This part of the project has been the most challenging to implement; and I've found myself chasing my tail, with nothing but dogged determinacy driving me forth.

On the emulator, I can display the actual Smith chart, fully labeled with these circular details in little over a second. But on the HHC it's way too slow.

Your suggestion takes my attempts in a better direction. If I can figure out how to realize your approach, it seems like it should be much faster. Would you happen to have any code snippets that accomplish something similar?

Thanks, for your suggestion!

-Dale-