Author Topic: Point offset in Polyline  (Read 2004 times)

0 Members and 1 Guest are viewing this topic.

FELIX

  • Bull Frog
  • Posts: 242
Point offset in Polyline
« on: February 22, 2023, 03:15:50 PM »
From a selected polyline and an informed distance X I select a point P1.
I want to have a point P1A and P1B as an offset.



OK.

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Point offset in Polyline
« Reply #1 on: February 22, 2023, 07:08:31 PM »
The easiest approach is to make use of the various vlax-curve-* functions, specifically: vlax-curve-getclosestpointto (to obtain a point on the polyline, given a point obtained from the user), vlax-curve-getparamatpoint (to determine the parameter of the point returned), & vlax-curve-getfirstderiv (to obtain the tangent vector at the given point).

From the tangent vector, you can calculate a perpendicular vector which may be scaled by the distance 'X', or alternatively, you can calculate the angle of the tangent vector, add/subtract pi/2 radians, and calculate the offset points using the polar function.

BIGAL

  • Swamp Rat
  • Posts: 1416
  • 40 + years of using Autocad
Re: Point offset in Polyline
« Reply #2 on: February 22, 2023, 07:25:09 PM »
Like Lee, for distance along a pline use  (vlax-curve-getpointatdist obj len)
A man who never made a mistake never made anything

xdcad

  • Bull Frog
  • Posts: 490
Re: Point offset in Polyline
« Reply #3 on: November 22, 2023, 05:03:48 PM »
The easiest approach is to make use of the various vlax-curve-* functions, specifically: vlax-curve-getclosestpointto (to obtain a point on the polyline, given a point obtained from the user), vlax-curve-getparamatpoint (to determine the parameter of the point returned), & vlax-curve-getfirstderiv (to obtain the tangent vector at the given point).

From the tangent vector, you can calculate a perpendicular vector which may be scaled by the distance 'X', or alternatively, you can calculate the angle of the tangent vector, add/subtract pi/2 radians, and calculate the offset points using the polar function.

Use code to translate the master’s words:

Code - Auto/Visual Lisp: [Select]
  1. ;|
  2. Suitable for calculating point offset on any curve
  3. single point
  4. |;
  5. (defun XD::Curve:OFSPnt (e pnt offsetx / pnt xdir ydir mat)
  6.   (setq pnt  (xdrx-getpropertyvalue e "getClosestPointTo" pnt)
  7.                                         ; closest point
  8.         xdir (xdrx-getpropertyvalue e "firstderiv" pnt)
  9.                                         ; tangent vector
  10.         ydir (xdrx-vector-perpvector xdir) ;vertical vector
  11.         mat  (xdrx-matrix-settranslation
  12.                (xdrx-vector-product ydir offsetx)
  13.                                         ; translation transformation matrix
  14.              )
  15.   )
  16.   (list (xdrx-point-transform pnt mat)  ; The transformation matrix is applied to the point
  17.         (xdrx-point-transform pnt (xdrx-matrix-inverse mat))
  18.   )
  19. )
  20. ;Multiple points, point table to find offset points
  21. (defun XD::Curve:OFSPnts (e pnts offsetx / pnt xdir ydir mat)
  22.   (mapcar '(lambda(x)(xd::curve:ofspnt e x offsetx)) pnts)
  23. )
« Last Edit: November 22, 2023, 11:20:39 PM by xdcad »
The code I wrote uses XDRX-API,which can be downloaded from github.com and is updated at any time.
===================================
https://github.com/xdcad
https://sourceforge.net/projects/xdrx-api-zip/
http://bbs.xdcad.net

kdub_nz

  • Mesozoic keyThumper
  • SuperMod
  • Water Moccasin
  • Posts: 2140
  • class keyThumper<T>:ILazy<T>
Re: Point offset in Polyline
« Reply #4 on: November 22, 2023, 05:13:00 PM »
@xdcad,

should the pnts parameter passed in be pnt ??
because of the 
(xdrx-getpropertyvalue e "getClosestPointTo" pnt)

(defun XD::Curve:OFSPnts (e pnts offsetx / pnt xdir ydir mat)

For Interest,
Why do you think the xdrx-xx method is better than the ActiveX method
Code - Auto/Visual Lisp: [Select]
  1. (vlax-curve-getClosestPointTo curve-obj givenPnt [extend])
https://help.autodesk.com/view/OARX/2023/ENU/?guid=GUID-90F585FE-D5C8-4C08-AFC7-A09A697EA52A

or using
Code - Auto/Visual Lisp: [Select]
  1. (vlax-get-property object property)
https://help.autodesk.com/view/OARX/2024/ENU/?guid=GUID-B3F22E35-4666-452F-89C8-5BC15B9E9463
« Last Edit: November 22, 2023, 07:11:55 PM by kdub_nz »
Called Kerry in my other life
Retired; but they dragged me back in !

I live at UTC + 13.00

---
some people complain about loading the dishwasher.
Sometimes the question is more important than the answer.

xdcad

  • Bull Frog
  • Posts: 490
Re: Point offset in Polyline
« Reply #5 on: November 22, 2023, 11:31:46 PM »
@xdcad,

should the pnts parameter passed in be pnt ??
because of the 
(xdrx-getpropertyvalue e "getClosestPointTo" pnt)

(defun XD::Curve:OFSPnts (e pnts offsetx / pnt xdir ydir mat)

For Interest,
Why do you think the xdrx-xx method is better than the ActiveX method
Code - Auto/Visual Lisp: [Select]
  1. (vlax-curve-getClosestPointTo curve-obj givenPnt [extend])
https://help.autodesk.com/view/OARX/2023/ENU/?guid=GUID-90F585FE-D5C8-4C08-AFC7-A09A697EA52A

or using
Code - Auto/Visual Lisp: [Select]
  1. (vlax-get-property object property)
https://help.autodesk.com/view/OARX/2024/ENU/?guid=GUID-B3F22E35-4666-452F-89C8-5BC15B9E9463

It doesn’t matter which method is better, XDRX or ActiveX
As long as it can catch mice, it's a good cat

XDRX API communicates directly with ARX, ActiveX needs to "go around a little further"
XDRX API is developed in applications, mainly to solve problems and be more "humane"

The LISP code written by XDRX is closer to the thinking of C++ ARX.
Including the processing methods of matrices, vectors, etc., regardless of efficiency, ARX is better in terms of legibility.
Because it is closer to a mathematical solution

In LISP, brackets within brackets make it difficult to see the logic clearly in many codes.

All roads lead to Rome

As for whether XDRX is good or bad, using it more may pay more attention to understanding.

XDRX API is the programming package of C++ ARX. In many cases, it is how to write C++ (ARX), and XDRX API is directly translated into LISP.
The code I wrote uses XDRX-API,which can be downloaded from github.com and is updated at any time.
===================================
https://github.com/xdcad
https://sourceforge.net/projects/xdrx-api-zip/
http://bbs.xdcad.net