The farthest X point and Y point

The farthest X point and Y point

cadking2k5
Advocate Advocate
4,257 Views
46 Replies
Message 1 of 47

The farthest X point and Y point

cadking2k5
Advocate
Advocate

here is a Ellipse drawn from Spline command Tangent doesn't work right on this is there a way to find the point that is the farthest X east and the farthest west X point and same North and South with Y

 

spline.JPG

0 Likes
4,258 Views
46 Replies
Replies (46)
Message 2 of 47

john.uhden
Mentor
Mentor

Do you mean?

 

a)  the farthest point on the object from a point somewhere/anywhere in the world, or

b)  the extents of the object. as in Xmin, Ymin, Xmax, Ymax.

 

If it's (a) then my first reaction is to iterate through its path in tiny increments to find the farthest point.

If it's (b) then it's a simple use of the vla-getboundingbox function.  But that will not necessarily return a point on the object, but rather the lower left and upper right corners of the minimum rectangle that would enclose it, in the WCS I think.

 

Please indicate your preference.

John F. Uhden

0 Likes
Message 3 of 47

DannyNL
Advisor
Advisor

There is an easier way to find the points on the ellipse compared to checking in small increments. From the calculated midpoint you can get the radius of the small axis  with vlax-curve-getClosestPointTo (and thus one of the quadrants). From there on you can calculate the other quadrants as well.

 

See code below.

This will return the corners of the bounding box, the midpoint and the quadrants of the ellipse in the order shown in the image.

 

(defun c:Test (/ T_Entity T_Object T_LowerLeft T_UpperRight T_LowerRight T_UpperLeft T_MidPoint T_Quad1 T_Quad2 T_Quad3 T_Quad4 T_Temp T_Return)   
   (if
      (setq T_Entity (entsel "\nSelect ellipse :"))
      (progn
         (setq T_Object (vlax-ename->vla-object (car T_Entity)))
         (vla-GetBoundingBox T_Object 'T_LowerLeft 'T_UpperRight)
         (setq T_LowerLeft  (vlax-safearray->list T_LowerLeft))
         (setq T_UpperRight (vlax-safearray->list T_UpperRight))
         (setq T_LowerRight (list (nth 0 T_UpperRight) (nth 1 T_LowerLeft)  0.0))
         (setq T_UpperLeft  (list (nth 0 T_LowerLeft)  (nth 1 T_UpperRight) 0.0))
         (setq T_MidPoint   (list (/ (+ (nth 0 T_LowerLeft) (nth 0 T_UpperRight)) 2) (/ (+ (nth 1 T_LowerLeft) (nth 1 T_UpperRight)) 2)))
         (setq T_Quad1      (vlax-curve-getClosestPointTo T_Object T_MidPoint))         
         (setq T_Quad2      (polar T_MidPoint (+ (angle T_MidPoint T_Quad1) pi) (distance T_MidPoint T_Quad1)))
         (setq T_Temp       (polar T_MidPoint (+ (angle T_MidPoint T_Quad1) (* 0.5 pi)) (distance T_MidPoint T_LowerLeft)))
         (setq T_Quad3      (vlax-curve-getClosestPointTo T_Object T_Temp))
         (setq T_Temp       (polar T_MidPoint (+ (angle T_MidPoint T_Quad1) (* 1.5 pi)) (distance T_MidPoint T_LowerLeft)))
         (setq T_Quad4      (vlax-curve-getClosestPointTo T_Object T_Temp))
         (setq T_Return     (list T_LowerLeft T_LowerRight T_UpperRight T_UpperLeft T_MidPoint))
         (setq T_Return     (append T_Return (vl-sort (list T_Quad1 T_Quad2 T_Quad3 T_Quad4) '(lambda (T_Item1 T_Item2) (< (angle T_MidPoint T_Item1) (angle T_MidPoint T_Item2))))))
;----- (setq T_OldOsmode (getvar "OSMODE")) (setvar "OSMODE" 0) (setq T_Count 0) (foreach T_Item T_Return (command "TEXT" T_Item "" "" (itoa (setq T_Count (1+ T_Count)))) ) (setvar "OSMODE" T_OldOsmode)
;----- ) ) T_Return )

 

PEllipsePoints.png

 

0 Likes
Message 4 of 47

Kent1Cooper
Consultant
Consultant

How about:  Get the bounding box and extract its lower left and upper right corners [lots of examples on this Forum], and draw Xlines both horizontally and vertically through each.

Kent Cooper, AIA
0 Likes
Message 5 of 47

marko_ribar
Advisor
Advisor

I couldn't find exactly what I wanted to show, but this lisp may help to obtain bounding box for ellipses / elliptical splines and so on, and then you only need to find intersection points with that rectangle and your curve either with (getpoint) with OSNAP=32 or through 'intersectwith method of Visual Lisp... Here is a lisp :

http://www.cadtutor.net/forum/showthread.php?68881-How-to-create-boundary-box-with-spline-entity/pag...

 

HTH., M.R.

Marko Ribar, d.i.a. (graduated engineer of architecture)
0 Likes
Message 6 of 47

marko_ribar
Advisor
Advisor

Here is what you actually wanted... Small but effective routine that does exactly what you need... Note that @DannyNL code is somewhat wrong...

 

(defun c:furthestX&Ypts ( / e ll ur p1 p2 p3 p4 ymin ymin1 ymin2 xmax xmax1 xmax2 ymax ymax1 ymax2 xmin xmin1 xmin2 )

  (vl-load-com)

  (setq e (car (entsel "\nPick reference 2d curve")))
  (if e
    (if (vl-catch-all-error-p (vl-catch-all-apply 'vlax-curve-getstartpoint (list e)))
      (progn
        (prompt "\nPicked entity doesn't belong to curve entities... Quitting, please select valid entity curve nex time...")
        (exit)
      )
    )
  )
  (if e
    (progn
      (vla-getboundingbox (vlax-ename->vla-object e) 'll 'ur)
      (mapcar 'set '(ll ur) (mapcar 'safearray-value (list ll ur)))
      (if (not (and (equal (caddr ll) 0.0 1e-6) (equal (caddr ur) 0.0 1e-6)))
        (progn
          (prompt "\nPicked curve not entirely placed in WCS plane... Quitting, please select valid entity curve next time...")
          (exit)
        )
      )
    )
  )
  (if e
    (progn
      (setq p1 (list (- (car ll) 0.1) (- (cadr ll) 0.1) 0.0))
      (setq p2 (list (+ (car ur) 0.1) (- (cadr ll) 0.1) 0.0))
      (setq p3 (list (+ (car ur) 0.1) (+ (cadr ur) 0.1) 0.0))
      (setq p4 (list (- (car ll) 0.1) (+ (cadr ur) 0.1) 0.0))
      (setq xmin1 (vlax-curve-getclosestpointtoprojection e p1 '(0.0 1.0 0.0)))
      (setq xmax1 (vlax-curve-getclosestpointtoprojection e p2 '(0.0 1.0 0.0)))
      (setq ymin1 (vlax-curve-getclosestpointtoprojection e p2 '(1.0 0.0 0.0)))
      (setq ymax1 (vlax-curve-getclosestpointtoprojection e p3 '(1.0 0.0 0.0)))
      (setq xmax2 (vlax-curve-getclosestpointtoprojection e p3 '(0.0 1.0 0.0)))
      (setq xmin2 (vlax-curve-getclosestpointtoprojection e p4 '(0.0 1.0 0.0)))
      (setq ymax2 (vlax-curve-getclosestpointtoprojection e p4 '(1.0 0.0 0.0)))
      (setq ymin2 (vlax-curve-getclosestpointtoprojection e p1 '(1.0 0.0 0.0)))
      (if (equal ymin1 ymin2 1e-6)
        (setq ymin ymin1)
      )
      (if (equal xmax1 xmax2 1e-6)
        (setq xmax xmax1)
      )
      (if (equal ymax1 ymax2 1e-6)
        (setq ymax ymax1)
      )
      (if (equal xmin1 xmin2 1e-6)
        (setq xmin xmin1)
      )
      (prompt "\nXmin : (") (princ (rtos (car xmin) 2 50)) (prompt " ") (princ (rtos (cadr xmin) 2 50)) (prompt " ") (princ (rtos (caddr xmin) 2 50)) (prompt ")")
      (prompt "\nXmax : (") (princ (rtos (car xmax) 2 50)) (prompt " ") (princ (rtos (cadr xmax) 2 50)) (prompt " ") (princ (rtos (caddr xmax) 2 50)) (prompt ")")
      (prompt "\nYmin : (") (princ (rtos (car ymin) 2 50)) (prompt " ") (princ (rtos (cadr ymin) 2 50)) (prompt " ") (princ (rtos (caddr ymin) 2 50)) (prompt ")")
      (prompt "\nYmax : (") (princ (rtos (car ymax) 2 50)) (prompt " ") (princ (rtos (cadr ymax) 2 50)) (prompt " ") (princ (rtos (caddr ymax) 2 50)) (prompt ")")
    )
  )
  (princ)
)

HTH., M.R.

Marko Ribar, d.i.a. (graduated engineer of architecture)
0 Likes
Message 7 of 47

DannyNL
Advisor
Advisor

And what is wrong in my code @marko_ribar?

Based on the information cadking2k5 has posted, my code gives what he asks and even more than that in the return list.

 

If you make such a statement it would be a nice thing to point out what exactly is wrong with it (without me having to ask). Or do I first have to give you a kudo before you tell me?

 

0 Likes
Message 8 of 47

marko_ribar
Advisor
Advisor

@DannyNL

I think that your code isn't wrong in the issue of working, but I think that OP is searching for different return list of points... Analyze this posted *.png and your and mine code - there is difference, and from my perspective I think that you just missed what OP wanted...

Marko Ribar, d.i.a. (graduated engineer of architecture)
0 Likes
Message 9 of 47

DannyNL
Advisor
Advisor

@marko_ribar

 

Yes, but if you had taken a good look at my code and what it returns then you would have seen that the format of the return list is:

 

  • LowerLeft_BoundingBox
  • LowerRight BoundingBox 
  • UpperRight BoundingBox
  • UpperLeft BoundingBox
  • CenterPoint Ellipse
  • Quadrant1 Ellipse
  • Quandrant2 Ellipse
  • Quandrant3 Ellipse
  • Quandrant4 Ellipse

 

Xmin can be retrieved from LowerLeft BB or UpperLeft BB

Xmax can be retrieved from LowerRight BB or UpperRight BB

Ymin can be retrieved from LowerLeft BB or LowerRight BB

Ymax can be retrieved from UpperLeft BB or UpperRight BB

 

So I'm still not convinced I've missed something and my code is 'wrong', since as I'd already stated based on the information of the first post my code returns everything asked and more.

0 Likes
Message 10 of 47

Kent1Cooper
Consultant
Consultant

@marko_ribar wrote:

.... obtain bounding box ... you only need to find intersection points with that rectangle and your curve either with (getpoint) with OSNAP=32 or through 'intersectwith method of Visual Lisp... .


That was my thought, too [in my case with the idea of Xlines both horizontally and vertically through the bounding-box corners, but a rectangle built on them would do].  But then I recalled that a Spline's bounding box can sometimes be outboard of its actual extent, which was true [slightly but meaningfully] when I made a Spline-form "ellipse" by Offsetting a true Ellipse.  But in experimenting even with an actual Ellipse entity, I find that if I draw a rectangle on its bounding box, even though in Zooming way in it looks  like it touches the Ellipse, neither  Osnap INTersection mode nor VLA (intersectwith) finds those locations!  So it seems the ClosestPointToProjection approach is the way to go.

Kent Cooper, AIA
0 Likes
Message 11 of 47

DannyNL
Advisor
Advisor

I stand corrected @marko_ribar!

 

With the information Kent provides in his last post I'm able to see the problem.

I'd never checked if the calculated points from the bounding box were actually on the ellipse. And although only a small deviation, the bounding box doesn't appear to touch the spline ellipse and there is no intersection between the box and the spline. So the Xmin, Xmax, Ymin, Ymax from the bounding box alone are close but not exactly on the ellipse and the vlax-curve-getclosestpointtoprojection in your routine is more accurate.

0 Likes
Message 12 of 47

john.uhden
Mentor
Mentor

You lost me.  What was all that other code for?  Seems to me that just LL and UR is/are the answer.

John F. Uhden

0 Likes
Message 13 of 47

Kent1Cooper
Consultant
Consultant

@john.uhden wrote:

You lost me.  What was all that other code for?  Seems to me that just LL and UR is/are the answer.


To get the farthest point on the ellipse  in each of the four compass directions, that is, if the bounding-box approach was viable, the points where the ellipse touches  the box.

Kent Cooper, AIA
0 Likes
Message 14 of 47

cadking2k5
Advocate
Advocate

@DannyNL @Kent1Cooper here is the bounding box of the Ellipse it is not a regular ellipse it is an Oblique Ellipse it is drawn with the SPLINE COMMAND

oblique ellipse.JPG

0 Likes
Message 15 of 47

marko_ribar
Advisor
Advisor

Your ellipse is actually circle presented from axonometric projection... In your first post you displayed ellipse differently than in your last posted picture... Without scaling parameters of Y axis and correct angle - in your case 45 degree (last picture) you can't really get Xmin and Xmax points... You can though use my posted code to find out Ymin and Ymax points, but all I can suggest is that you try to reconstruct circle in 1st orthogonal projection from your axonometry from obtained Ymin and Ymax points and in case that it's impossible to create real rotated ellipse which is possible if oblique projection <XoY=30 degree no scaling (ellipse rotated around center for 15 degree), you'll have to reconstruct parameters of axonometry XoY axis angle and scale factor along Y axis in case that X axis scale factor is real and correct one (no shortening)... I'll attach one DWG with circle/ellipse in this so called uniform oblique projection that is showing that your oblique ellipse is real one just rotated around center for 15 degree given the fact that XY angle of projection is 30 degree and there are no scaling factors between X and Y projection axis...

 

Conclusion : theoretically it's possible to get Xmin and Xmax points if you can reconstruct parameters of projection - if it's isometric projection or any other vector projection than it's easy one - it's real ellipse without rotation and you can reconstruct any parallelogram with rhombic view and proclaim that that ellipse is in vector projection with Xmin, Xmax, Ymin and Ymax points depended from so called orthogonal Y axis shortening (circle->real ellipse transformation) - Xmin and Ymin points would then be placed on left edge of inscribed rectangle that is real offset of enclosing one and Xmax and Ymax on the right edge similar... If your projection is actually oblique than this is not so obvious to reconstruct without parameters of projection - Ymin and Ymax points though you can get if X axis of projection is like in your example parallel to X axis of WCS or normal orthogonal top view projection - angle = 0.0 degree...

Marko Ribar, d.i.a. (graduated engineer of architecture)
0 Likes
Message 16 of 47

marko_ribar
Advisor
Advisor

circle in vector projection.png

 

 

HTH, M.R.

Marko Ribar, d.i.a. (graduated engineer of architecture)
0 Likes
Message 17 of 47

john.uhden
Mentor
Mentor

I did not see "on the ellipse" in the OP's post.  He just wanted Xmin, Xmax, Ymin, and Ymax (in my terms).

That would be represented by two (2) points (Xmin Ymin) and (Xmax Ymax) or LL and UR.

At no matter what angle, neither of those points can fall ON an ellipse, well unless an ellipse can have a zero-length radius, which it apparently can't, at least in 2002.

John F. Uhden

0 Likes
Message 18 of 47

cadking2k5
Advocate
Advocate

@marko_ribar that works on regular Oblique Ellipse but not Cabinet Oblique Ellipse that are drawn at have the dept 

0 Likes
Message 19 of 47

marko_ribar
Advisor
Advisor

@cadking2k5

So you said that you drew splined ellipse or elliptical spline... So what is it then : spline or ellipse? And what actually you want to achieve? If it's circle in oblique projection - you have to know parameters of projection to obtain needed data... I mean how can computer determine what enclosing parallelogram is correct one? And how do you know that "that" works on regular oblique projection and not on cabinet? What you showed certainly is circle in oblique projection or normal rotated ellipse in WCS regular orthogonal projection - it isn't and I agree that is not and ellipse or circle viewed from perspective projection, but it is one of those viewed in parallel projection...

Marko Ribar, d.i.a. (graduated engineer of architecture)
0 Likes
Message 20 of 47

marko_ribar
Advisor
Advisor

Just to show you that no matter what parallel projection you use, when you transform circle from WCS projection, you'll always get an ellipse... I segmented circle up to 360 segments, and after that I used transformation routine for transforming polylines/meshes to axonometry - I used Xaxis angle=0.0 Xscale factor=1.0 Yaxis angle=240.0 Yscale factor=1.5 Zaxis angle=90.0 Zscale factor=1.0 (Zaxis parameters aren't important)... After circle was transformed, I reconstructed parallelogram and as I also had routine for determining minboundingbox, I converted transformed old heavy polyline (transformed segmented circle) into region after which I applied my routine... I've got enclosing rectangle rotated little more than 45 degree... Then I redraw real ellipse with ellipse command, and I leave it to you to proclaim that those region and ellipse are exact match... So it's always an ellipse IMHO... See it for yourself from attached example...

 

M.R.

Marko Ribar, d.i.a. (graduated engineer of architecture)
0 Likes