Recent

Author Topic: Any support for Perpendicular Lines  (Read 856 times)

SandyG

  • Jr. Member
  • **
  • Posts: 92
Any support for Perpendicular Lines
« on: September 11, 2024, 01:30:36 am »
Looked around but didn't see (might have missed it) Perpendicular lines from 2 points on another line, with one of the points being used for the end of the perpendicular line and then I can draw a polygon in the right angle/orientation around an arc of the gauge.

Before I do more math, was checking to see if it exists.

My fallback is to calc the slope of the line, - and inverse to get the perpendicular slope, then come up with the y=mx+b stuff. This does have some problems with lines that are vertical and such, but can work that out.

Trying to draw a triangle marker that indicates the Max (or Min) of the pointer on the gauge. The example is just a line but would like to draw the line as a upside down right triangle of sorts.

Sandy

circular

  • Hero Member
  • *****
  • Posts: 4356
    • Personal webpage
Re: Any support for Perpendicular Lines
« Reply #1 on: September 11, 2024, 01:07:16 pm »
Hi SandyG,

If you have a segment defined by two points A and B, then you can compute a vector u from A to B. Then from that you can build a vector v that is perpendicular. By adding this vector to a point, you will get the end of the new segment.

Code: Pascal  [Select][+][-]
  1. uses BGRABitmapTypes;
  2. var
  3.   A,B,C : TPointF;
  4.   u,v : TPointF;
  5. begin
  6.   // given segment AB
  7.   A := PointF(5, 5);
  8.   B := PointF(10, 5);
  9.   // vector from A to B
  10.   u := B - A; // = (5, 0)
  11.   // build the perpendicular vector
  12.   // (clockwise in screen coordinates while the opposite would be counter clockwise)
  13.   v := PointF(-u.y, u.x); // = (0, 5)
  14.   // you can scale it to set the new segment length
  15.   v := v * (10 / VectLen(v)); // = (0, 10)
  16.   C := B + v; // = (10, 15)
  17. end;
  18.  

Alternatively, you can rotate a vector by any angle by using an affine matrix.
Code: Pascal  [Select][+][-]
  1. uses BGRATransform;
  2. begin
  3.   ...
  4.   v := AffineMatrixRotationDeg(90) * u;
  5.   ...
  6. end;
  7.  

Regards
Conscience is the debugger of the mind

SandyG

  • Jr. Member
  • **
  • Posts: 92
Re: Any support for Perpendicular Lines
« Reply #2 on: September 11, 2024, 07:32:22 pm »
Awesome!!

I will give the Vector version a try, looks pretty straight forward.

Trying to get the last of the features into the gauge then to clean up the range and related scaling as right now it's only good for 0-100. Slowly getting it done  :)

Thanks again, this will keep it moving forward!

Sandy

circular

  • Hero Member
  • *****
  • Posts: 4356
    • Personal webpage
Re: Any support for Perpendicular Lines
« Reply #3 on: September 11, 2024, 09:05:59 pm »
I am glad I could help  :)
Conscience is the debugger of the mind

 

TinyPortal © 2005-2018