How to extend a line segment both direction

djtoshi182's icon

Hello.

This appears more Math question, sadly I'm not good at.
If a line segment between (x1,y1) and (x2,y2) and the slope is defined, how to extend the line to both direction while maintaining the slope?
i.e)
a line between (150, 50) and (40, 140)
is drawn on 200, 200 jit.lcd matrix,
how to extend both end of the line to the edge of 200, 200 lcd?

my goal is to maintain the both ends of the line segment attached to the 200,200 lcd edges while the line segment rotating.

Best,

Floating Point's icon

if (150, 50) and (40, 140)
are (x1, y1) and (x2, y2)

then when x is 0,
y0 = y1 - x1* (y2-y1)/(x2-x1)
so that's one edge.

when x = 200, then y will be:
200*(y2-y1)/(x2-x1) + y0

so, for illustration, y0 =50-150(90/-110)= -72.7
and when x = 200, y= 200*90/-110 - 72.7=-236.3

anyway try it out see if it works

djtoshi182's icon

Thanks for the response with math formula, could you help me with the formular to be done in Max?
the (x1,y1) & (x2,y2) of line segment is floating around in the 200 x 200 jit.lcd box, generate a linesegment everytime based on the changing coords and scaled to be disaplyed withtin the 200 x 200 sized lcd.
and I'd need the line segment extended to the edges of 200x200, go beyond the visible lcd box, so the both ends of the line segment become not visible in the lcd box.

Best,

Roman Thilenius's icon


y0= y1 - x1* (y2-y1)/(x2-x1)

expr $f1* ($f4-$f2) / ($f3-$f1)

this is basically linear 2d mapping which is mathematically the same as range mapping.

not sure if they finally fixed inversion mode in zmap and scale, if yes, then these objects will do this, too.

-110

djtoshi182's icon

Thank you!!

djtoshi182's icon

I have a follow up question.
I have successfully extended a line from two coords to fit the 200x200 lcd box.
Now I'd like to tile each box to 10 x 10 grids on a 2000x2000 matrix, while the lines from each cells are extended over the entire matrix.
I've tried to make each boxes to have 4000x4000 with extended lines, then place each lcd box tiled on 10x10 grid. It doesn't seem to work without assigning the anchor for each cells. Can the line-extension formular applied after tiled up 100 lcd boxes?

Roman Thilenius's icon

it is bit tricky, i needed three attempts myself.

#P window setfont "Sans Serif" 12.;
#P window linecount 1;
#P comment 568 242 105 9109516 x2 y2 min 0;
#B color 12;
#P comment 342 242 105 9109516 x1 y1 max 0;
#B color 12;
#P comment 454 169 105 9109516 x1 y2 y1 x2;
#B color 12;
#P comment 680 98 105 9109516 min;
#B color 12;
#P comment 454 98 105 9109516 max;
#B color 12;
#P window setfont "Sans Serif" 24.;
#P comment 654 28 63 9109528 4;
#P comment 433 28 63 9109528 3;
#P comment 238 28 63 9109528 2;
#P window setfont "Sans Serif" 9.;
#P newex 501 209 173 9109513 pak linesegment 40 140 0 0;
#P newex 281 210 173 9109513 pak linesegment 150 50 200 0;
#P message 661 69 50 9109513 0;
#P newex 661 138 133 9109513 scale 150 40 50 140;
#P message 441 69 50 9109513 200;
#P message 169 69 209 9109513 linesegment 150 50 40 140 100 200 200;
#P message 46 69 103 9109513 brgb 0 50 50 \, clear;
#P newex 120 303 50 9109513 t l clear;
#P user lcd 200 338 200 200 1 1 0 0 0;
#P newex 441 137 133 9109513 scale 150 40 50 140;
#P window setfont "Sans Serif" 24.;
#P comment 62 28 63 9109528 1;
#P window setfont "Sans Serif" 12.;
#P comment 218 98 105 9109516 x1 y1 x2 y2;
#B color 12;
#P connect 5 0 4 0;
#P connect 10 0 3 0;
#P connect 11 0 3 0;
#P connect 6 0 3 0;
#P connect 4 0 3 0;
#P connect 4 1 3 0;
#P connect 7 0 2 0;
#P connect 2 0 10 4;
#P connect 9 0 8 0;
#P connect 8 0 11 4;
#P window clipboard copycount 20;

mapping coordinates at another blue monday

Roman Thilenius's icon

p.s. you might want to use floating point numbers.

regarding "cells", i guess there is no better way than having an anchor or offset parameter for each of them.

a single coordinate system is already a brainfuck, then in lcd Y is negative and the first line inside is 0 instead of 1.

it is worth here to let the CPU calculate few more numbers in order to get things right in the brain.

if you create a generic anchor/offset system first you might want to use different lcd objects as cells later?

Roman Thilenius's icon

uh, actually you _must use floating point, my bad :)

djtoshi182's icon

Thank you so much!

djtoshi182's icon

Hello.

I have revisited this example. Roman's patch works itself, but doesn't work with my float values.
Is there a reason to this?

Max Patch
Copy patch and select New From Clipboard in Max.

temp account's icon

you have your y1 and y2 swapped:

Max Patch
Copy patch and select New From Clipboard in Max.

djtoshi182's icon

Thank you!