Author Topic: Calculate the coordinates of the point  (Read 4683 times)

0 Members and 1 Guest are viewing this topic.

andy_lee

  • Newt
  • Posts: 147
Calculate the coordinates of the point
« on: February 08, 2017, 05:46:07 AM »
Dear All

Known  offset value D1 and D2 , Pick 2 line , Calculate the coordinates of the point "P"

Line1 and Line 2 must have a intespoint . if not inters , prompt 
Line1 and Line2 maybe is A portion of a polyline.

Code: [Select]
(setq *D1* 10)
(setq *D2* 15)

(setq L1 (entsel "\n>>>Pick First line :"))
(setq L2 (entsel "\n>>>Pick Second line :"))

......

Thanks for any help !
andy.
Best regards.

andy_lee

  • Newt
  • Posts: 147
Re: Calculate the coordinates of the point
« Reply #1 on: February 08, 2017, 06:02:22 AM »
Oh! Post wrong place , Administrator , Please help me  move  it to “AutoLISP (Vanilla / Visual)”  ,Thank you !
andy.
Best regards.

Lee Mac

  • Seagull
  • Posts: 12913
  • London, England
Re: Calculate the coordinates of the point
« Reply #2 on: February 08, 2017, 12:45:06 PM »
  • Obtain the endpoints of each selected line
  • Calculate the line intersection point (using inters with the end points)
  • Calculate a unit vector from the intersection point to the opposite end point of each line
  • Scale each vector by the require distance (d1 & d2)
  • Add the vectors to obtain the required point.

andy_lee

  • Newt
  • Posts: 147
Re: Calculate the coordinates of the point
« Reply #3 on: February 08, 2017, 09:04:03 PM »
Hi
Lee  Thank you for help!

Sometime the result is wrong. why?

Code: [Select]
(vl-load-com)
(setq *D1* 10)
(setq *D2* 15)
(setq L1(entsel "\n>>>Pick First Line:"))
(setq L2(entsel "\n>>>Pick Second Line:"))
(setq pt1(vlax-curve-getClosestPointTo(vlax-ename->vla-object(car L1))(cadr L1)nil))
(setq pt2(vlax-curve-getClosestPointTo(vlax-ename->vla-object(car L2))(cadr L2)nil))
(setq interpoint
      (inters
          pt1(polar pt1(+(angle(cadr L1)pt1)(* 0.5 pi)) 5.0)
          pt2(polar pt2(+(angle(cadr L2)pt2)(* 0.5 pi)) 5.0)
          nil
       )
)
(setq pt1-1 (polar pt1(angle interpoint pt2) *D1*))
(setq pt2-1 (polar pt2(angle interpoint pt1) *D2*))
(setq p
      (inters
           pt1-1(polar pt1-1(+ (angle pt1-1 pt1) (* 0.5 pi)) 5)
           pt2-1(polar pt2-1(+ (angle pt2-1 pt2) (* 0.5 pi)) 5)
           nil
       )
)

andy.
Best regards.

Hugo

  • Bull Frog
  • Posts: 430
Re: Calculate the coordinates of the point
« Reply #4 on: February 09, 2017, 12:59:36 AM »
At with it goes. 

Bei mit geht es.

Code: [Select]
(setq *D1* 10)
(setq *D2* 15)
(setq L1(entsel "\n>>>Pick First Line:"))
(setq L2(entsel "\n>>>Pick Second Line:"))
(setq pt1(vlax-curve-getClosestPointTo(vlax-ename->vla-object(car L1))(cadr L1)nil))
(setq pt2(vlax-curve-getClosestPointTo(vlax-ename->vla-object(car L2))(cadr L2)nil))
(setq interpoint
      (inters
          pt1(polar pt1(+(angle(cadr L1)pt1)(* 0.5 pi)) 5.0)
          pt2(polar pt2(+(angle(cadr L2)pt2)(* 0.5 pi)) 5.0)
          nil
       )
)
(setq pt1-1 (polar pt1(angle interpoint pt2) *D1*))
(setq pt2-1 (polar pt2(angle interpoint pt1) *D2*))
(setq p
      (inters
           pt1-1(polar pt1-1(+ (angle pt1-1 pt1) (* 0.5 pi)) 5)
           pt2-1(polar pt2-1(+ (angle pt2-1 pt2) (* 0.5 pi)) 5)
           nil
       )
)



(defun Circle (cen rad)
  (entmakex (list (cons 0 "CIRCLE")
                  (cons 10 cen)
                  (cons 40 rad))))

(Circle p 1)

Hugo

  • Bull Frog
  • Posts: 430
Re: Calculate the coordinates of the point
« Reply #5 on: February 09, 2017, 08:04:17 AM »
When I click on a line in the X-Ref klick I get also an error message   :-o

; error: bad argument value: AcDbCurve 42

Hugo

  • Bull Frog
  • Posts: 430
Re: Calculate the coordinates of the point
« Reply #6 on: February 09, 2017, 12:30:03 PM »
Can wehel help you the lines also in an X-Ref can click.
"Nentsel" does not go unfortunately.    :-o

Thank you   :-)


Kann wehr Helfen das man die Linien auch in einer X-Ref anklicken kann.
"nentsel"  geht leider nicht.

Danke

andy_lee

  • Newt
  • Posts: 147
Re: Calculate the coordinates of the point
« Reply #7 on: February 09, 2017, 08:17:08 PM »
At with it goes. 

Bei mit geht es.

Code: [Select]
(setq *D1* 10)
(setq *D2* 15)
(setq L1(entsel "\n>>>Pick First Line:"))
(setq L2(entsel "\n>>>Pick Second Line:"))
(setq pt1(vlax-curve-getClosestPointTo(vlax-ename->vla-object(car L1))(cadr L1)nil))
(setq pt2(vlax-curve-getClosestPointTo(vlax-ename->vla-object(car L2))(cadr L2)nil))
(setq interpoint
      (inters
          pt1(polar pt1(+(angle(cadr L1)pt1)(* 0.5 pi)) 5.0)
          pt2(polar pt2(+(angle(cadr L2)pt2)(* 0.5 pi)) 5.0)
          nil
       )
)
(setq pt1-1 (polar pt1(angle interpoint pt2) *D1*))
(setq pt2-1 (polar pt2(angle interpoint pt1) *D2*))
(setq p
      (inters
           pt1-1(polar pt1-1(+ (angle pt1-1 pt1) (* 0.5 pi)) 5)
           pt2-1(polar pt2-1(+ (angle pt2-1 pt2) (* 0.5 pi)) 5)
           nil
       )
)



(defun Circle (cen rad)
  (entmakex (list (cons 0 "CIRCLE")
                  (cons 10 cen)
                  (cons 40 rad))))

(Circle p 1)


Hello
I can't see any change,  you just add a test function?
andy.
Best regards.

andy_lee

  • Newt
  • Posts: 147
Re: Calculate the coordinates of the point
« Reply #8 on: February 09, 2017, 09:58:02 PM »
  • Obtain the endpoints of each selected line
  • Calculate the line intersection point (using inters with the end points)
  • Calculate a unit vector from the intersection point to the opposite end point of each line
  • Scale each vector by the require distance (d1 & d2)
  • Add the vectors to obtain the required point.

I can't understand No.3. what is unit vector?
andy.
Best regards.

kdub_nz

  • Mesozoic keyThumper
  • SuperMod
  • Water Moccasin
  • Posts: 2132
  • class keyThumper<T>:ILazy<T>
Re: Calculate the coordinates of the point
« Reply #9 on: February 10, 2017, 12:02:57 AM »

If you consider a vector has a distance and a direction, the direcrion can be expressed by an X distance and a Y distance,
and the hypotenuse of the triangle formed is the vector distance.

A unit vector has the triangle hypotenuse reduced to one unit with the X and Y distances modified accordingly.

This may help :
https://www.khanacademy.org/math/precalculus/vectors-precalc/unit-vectors/v/unit-vector-intro
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.

Hugo

  • Bull Frog
  • Posts: 430
Re: Calculate the coordinates of the point
« Reply #10 on: February 10, 2017, 12:22:09 AM »
Here my test


Code: [Select]
(defun c:Test ( /)
(vl-load-com)
  (setq *D1* (getreal "\nAbstand von Wand D1 eingeben: "))
  (setq *D2* (getreal "\nAbstand von Wand D2 eingeben: "))    
;;(setq *D1* 10)
;;(setq *D2* 15)
(setq L1(entsel "\n>>>Pick First Line:"))
(setq L2(entsel "\n>>>Pick Second Line:"))
(setq pt1(vlax-curve-getClosestPointTo(vlax-ename->vla-object(car L1))(cadr L1)nil))
(setq pt2(vlax-curve-getClosestPointTo(vlax-ename->vla-object(car L2))(cadr L2)nil))
(setq interpoint
      (inters
          pt1(polar pt1(+(angle(cadr L1)pt1)(* 0.5 pi)) 5.0)
          pt2(polar pt2(+(angle(cadr L2)pt2)(* 0.5 pi)) 5.0)
          nil
       )
)
(setq pt1-1 (polar pt1(angle interpoint pt2) *D1*))
(setq pt2-1 (polar pt2(angle interpoint pt1) *D2*))
(setq p
      (inters
           pt1-1(polar pt1-1(+ (angle pt1-1 pt1) (* 0.5 pi)) 5)
           pt2-1(polar pt2-1(+ (angle pt2-1 pt2) (* 0.5 pi)) 5)
           nil
       )
)
(Circle p 10)
);defun


(defun Circle (cen rad)
  (entmakex (list (cons 0 "CIRCLE")
                  (cons 10 cen)
                  (cons 40 rad))))

Hugo

  • Bull Frog
  • Posts: 430
Re: Calculate the coordinates of the point
« Reply #11 on: February 10, 2017, 12:23:27 AM »
Q kdub    :? :? :?

kdub_nz

  • Mesozoic keyThumper
  • SuperMod
  • Water Moccasin
  • Posts: 2132
  • class keyThumper<T>:ILazy<T>
Re: Calculate the coordinates of the point
« Reply #12 on: February 10, 2017, 12:32:55 AM »
Q kdub    :? :? :?

You have a problem with my response Hugo ??
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.

Hugo

  • Bull Frog
  • Posts: 430
Re: Calculate the coordinates of the point
« Reply #13 on: February 10, 2017, 01:06:05 AM »
Yeah I'm too high for me   :cry: :cry: :cry:


Ja ich das ist zu hoch für mich

andy_lee

  • Newt
  • Posts: 147
Re: Calculate the coordinates of the point
« Reply #14 on: February 10, 2017, 01:07:33 AM »
Here my test


Code: [Select]
(defun c:Test ( /)
(vl-load-com)
  (setq *D1* (getreal "\nAbstand von Wand D1 eingeben: "))
  (setq *D2* (getreal "\nAbstand von Wand D2 eingeben: "))    
;;(setq *D1* 10)
;;(setq *D2* 15)
(setq L1(entsel "\n>>>Pick First Line:"))
(setq L2(entsel "\n>>>Pick Second Line:"))
(setq pt1(vlax-curve-getClosestPointTo(vlax-ename->vla-object(car L1))(cadr L1)nil))
(setq pt2(vlax-curve-getClosestPointTo(vlax-ename->vla-object(car L2))(cadr L2)nil))
(setq interpoint
      (inters
          pt1(polar pt1(+(angle(cadr L1)pt1)(* 0.5 pi)) 5.0)
          pt2(polar pt2(+(angle(cadr L2)pt2)(* 0.5 pi)) 5.0)
          nil
       )
)
(setq pt1-1 (polar pt1(angle interpoint pt2) *D1*))
(setq pt2-1 (polar pt2(angle interpoint pt1) *D2*))
(setq p
      (inters
           pt1-1(polar pt1-1(+ (angle pt1-1 pt1) (* 0.5 pi)) 5)
           pt2-1(polar pt2-1(+ (angle pt2-1 pt2) (* 0.5 pi)) 5)
           nil
       )
)
(Circle p 10)
);defun


(defun Circle (cen rad)
  (entmakex (list (cons 0 "CIRCLE")
                  (cons 10 cen)
                  (cons 40 rad))))

Hi
I can't see any change again,This code applies only to the rectangle
you can draw 2 line test.
andy.
Best regards.

Hugo

  • Bull Frog
  • Posts: 430
Re: Calculate the coordinates of the point
« Reply #15 on: February 10, 2017, 01:15:15 AM »
Yes for rectangles, lines and poly is with me.

Then I understand something wrong?  :-(
For X-Ref it is unfortunately not?   :-(


Ja für Rechtecke, Linien und Poly geht es bei mir.

Dann verstehe ich was falsch ?
Für X-Ref geht es leider nicht ?
« Last Edit: February 10, 2017, 01:20:42 AM by Hugo »

andy_lee

  • Newt
  • Posts: 147
Re: Calculate the coordinates of the point
« Reply #16 on: February 10, 2017, 01:28:41 AM »
The result only rectangle is right ! because the angle is 90
you can draw 2 line . the angle is not 90. test again
andy.
Best regards.

Hugo

  • Bull Frog
  • Posts: 430
Re: Calculate the coordinates of the point
« Reply #17 on: February 10, 2017, 01:36:52 AM »
Hier


andy_lee

  • Newt
  • Posts: 147
Re: Calculate the coordinates of the point
« Reply #18 on: February 10, 2017, 01:42:48 AM »
andy.
Best regards.

Hugo

  • Bull Frog
  • Posts: 430
Re: Calculate the coordinates of the point
« Reply #19 on: February 10, 2017, 01:47:25 AM »
OK now I understand.
This is not true.   :embarrassed:

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8691
  • AKA Daniel
Re: Calculate the coordinates of the point
« Reply #20 on: February 10, 2017, 02:10:16 AM »

If you consider a vector has a distance and a direction, the direcrion can be expressed by an X distance and a Y distance,
and the hypotenuse of the triangle formed is the vector distance.

A unit vector has the triangle hypotenuse reduced to one unit with the X and Y distances modified accordingly.

This may help :
https://www.khanacademy.org/math/precalculus/vectors-precalc/unit-vectors/v/unit-vector-intro

unit vectors have little hats

kdub_nz

  • Mesozoic keyThumper
  • SuperMod
  • Water Moccasin
  • Posts: 2132
  • class keyThumper<T>:ILazy<T>
Re: Calculate the coordinates of the point
« Reply #21 on: February 10, 2017, 02:43:53 AM »
Yep ... a party hat.


but just to show they are not all frivolous ...

Consider a unit vector with a direction of 30 degrees.

cos(30) is 0.8660 which is the x offset
sin(30) is 0.50 which is the Y offset.

similarly cos(45) and sin(45) are both 0,7071  which is the the x an Y offset from the startpoint.

//------------------

My old math master used to say something like " the universe is made up of circles and triangles"
... I've since come to understand that he wasn't really joking.
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.

andy_lee

  • Newt
  • Posts: 147
Re: Calculate the coordinates of the point
« Reply #22 on: February 10, 2017, 04:12:53 AM »
Still can't understand. my math is so bad.
Math master and Lisp master .please give a fish.
@Lee Mac @ribarm @roy_043  ....
andy.
Best regards.

kdub_nz

  • Mesozoic keyThumper
  • SuperMod
  • Water Moccasin
  • Posts: 2132
  • class keyThumper<T>:ILazy<T>
Re: Calculate the coordinates of the point
« Reply #23 on: February 10, 2017, 04:20:21 AM »
Quote
I can't understand No.3. what is unit vector?

You're welcome.

Quote
... my math is so bad.

Well, do something about it.


I'm outa here.


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.

andy_lee

  • Newt
  • Posts: 147
Re: Calculate the coordinates of the point
« Reply #24 on: February 10, 2017, 05:14:47 AM »
This I do:
https://www.theswamp.org/index.php?topic=52652.msg575395#msg575395

I want use Lee's method. but I can't understand.
andy.
Best regards.

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8691
  • AKA Daniel
Re: Calculate the coordinates of the point
« Reply #25 on: February 10, 2017, 07:20:49 AM »
Yep ... a party hat.

Joking aside, thanks for the link  8-)