Author Topic: PixelMath vector line  (Read 328 times)

Offline PepeChambo

  • Newcomer
  • Posts: 9
    • View Profile
    • Cometografía
PixelMath vector line
« on: 2019 November 16 11:12:51 »
I don't know if is possible any formula for plot lines as vectors in PixelMath, something as:

line(x_orig,y_orig,vector_angle,longitude).

Regards.
Pepe Chambó
Cometografia.es

Offline oldwexi

  • PixInsight Guru
  • ****
  • Posts: 625
    • View Profile
    • Astronomy Pages G.W.
Re: PixelMath vector line
« Reply #1 on: 2019 November 17 07:18:49 »
Hi Pepe!
I hope i did not misunderstand your question concerning drawing vectors with PixelMath
So, I dont know a vector function in PixelMath directly.

But,
there is a function in PixelMath to create a line segment.
Its called d2seg and it draws a line from x_orig,y_orig,    to     x_target,y_target.
Simply test it with

d2seg(100,100,    200,200)
will draw a line segment from x=100,y=100  to X=200,y=200

So, to use your arguments Angle and length you can extend the formula by calculating
the target x,y  by using Sin and Cos

To make the formula standard and only change the variables you
define in PixelMath  in
Symbols: xv=100, yv=100, va=45,  l=100, xv1, yv1
And the PixelMath expression than is:
xv1=(cos((va/180*pi())  ) * l); yv1=(sin((va/180*pi())  )*l); 1-d2seg(xv,yv,xv+xv1,yv-yv1)

For future segment drawings simply change the values in the Symbols and you get a line segment
depending on the angle va and the length l.
in the final expression i wrote 1-d2seg(....    to create a one pixel wide white line with black background  if you only us
d2seg(...  you will get a black line with white background

if there are questions let me know.

Yes you could extend this formula by using the width and height infos of the actual image
to place the start x,y  calculated...   etc...

Gerald

Offline PepeChambo

  • Newcomer
  • Posts: 9
    • View Profile
    • Cometografía
Re: PixelMath vector line
« Reply #2 on: 2019 November 18 03:53:55 »
First of all, thanks for your response :)

Following your example I tried width this...

Expressions
xv1=(cos((va/180*pi())  ) * l); yv1=(sin((va/180*pi())  )*l); d=d2seg(xv,yv,xv+xv1,yv-yv1); iif(d==0,1,$T)
Symbols
xv=100, yv=100, va=45,  l=100, xv1, yv1, d

Mainly it works tracing with angle and lenght indicated, but the line appears doted and seems a "Starlink trace"  :D

I have to investigate what is the problem.


Regards.
Pepe Chambó
Cometografia.es

Offline oldwexi

  • PixInsight Guru
  • ****
  • Posts: 625
    • View Profile
    • Astronomy Pages G.W.
Re: PixelMath vector line
« Reply #3 on: 2019 November 18 05:41:20 »
Hallo Pepe!
The dotted line comes when the thickness of the line is only one (1) pixel wide.
The display and the SW have to interpolate as it cannot display a vector it can only display pixels.
so the more nearer to  diagonal direction the more dotted. (All Digital images are in pixels and not vectors
as do also the other astro image processing programs)

If you enter the formula with
2-d2seg(.......) you get a 2 pixel thick line segment
3-d2seg(.......) you get a 3 pixel line segment  etc...

Gerald


Offline Juan Conejero

  • PTeam Member
  • PixInsight Jedi Grand Master
  • ********
  • Posts: 7089
    • View Profile
    • http://pixinsight.com/
Re: PixelMath vector line
« Reply #4 on: 2019 November 18 10:32:11 »
Alternatively, the following script can be used with greater flexibility:

Code: [Select]
#include <pjsr/PenCap.jsh>
#include <pjsr/PenStyle.jsh>

#define X         1000        // X pixel coordinate of the starting point
#define Y         1000        // Y pixel coordinate of the starting point
#define LENGTH    1000        // Line length in pixels
#define ANGLE     30          // Position angle in degrees
#define PEN_WIDTH 10          // Pen width in pixels
#define PEN_COLOR 0xffffffff  // Pen color (AARRGGBB)

function drawLinePolar( image, x, y, angle, length, penWidth, penColor )
{
   if ( penWidth == undefined )
      penWidth = 1.0;
   if ( penColor == undefined )
      penColor = 0xffffffff; // solid white

   angle = Math.rad( angle );
   
   let b = new Bitmap( image.width, image.height );
   b.fill( 0 ); // transparent
   let g = new VectorGraphics( b );
   g.pen = new Pen( penColor, penWidth, PenStyle_Solid, PenCap_Round );
   g.antialiasing = true;
   g.drawLine( x, y, x + length*Math.cos( angle ), y - length*Math.sin( angle ) );
   g.end();
   image.blend( b );
}

function main()
{
   let view = ImageWindow.activeWindow.mainView;
   if ( view.isNull )
      throw new Error( "No active image." );
   view.beginProcess();
   drawLinePolar( view.image, X, Y, ANGLE, LENGTH, PEN_WIDTH, PEN_COLOR );
   view.endProcess();
}

main();

The script will draw an antialiased line (i.e., without staircase artifacts) on the current image. Pen colors are encoded in AARRGGBB format, where AA=alpha (transparency), RR=red, GG=green and BB=blue. Each component is an hexadecimal pixel value in 8-bit range. For example:

Solid black:
0xff000000

Solid red:
0xffff0000

Solid green:
0xff00ff00

Solid blue:
0xff0000ff

Translucent (50%) orange:
0x80ff8000

I hope this is useful for what you want to do.
Juan Conejero
PixInsight Development Team
http://pixinsight.com/