How to Solve this Text value is outside of object

How to Solve this Text value is outside of object

jaimuthu
Advocate Advocate
563 Views
5 Replies
Message 1 of 6

How to Solve this Text value is outside of object

jaimuthu
Advocate
Advocate

1) I want Triangle T1 T2 T3

2) I run program TRI command for T1 Triangle in UCS World position T1 Triangle is good for the shape and distance

3) I run program TRI command for T2 Triangle in UCS World position T2 Triangle shape and distance is rong
but text value is aligned to the object

4) I run program TRI command for T2 Triangle Change in UCS "3" Point method T2 Triangle shape is correct distance ,But text value is Outside of object

____________________________________________________________________________________________

(defun c:tri( / unit mxv v^v transptucs transptwcs p1 p2 loop g p h gp p3 )

(defun unit ( v / d )
(mapcar '(lambda ( x y ) (/ x y)) v (list (setq d (distance '(0.0 0.0 0.0) v)) d d))
)

(defun mxv ( m v )
(mapcar '(lambda ( r ) (apply '+ (mapcar '* r v))) m)
)

(defun v^v ( u v )
(list
(- (* (cadr u) (caddr v)) (* (cadr v) (caddr u)))
(- (* (car v) (caddr u)) (* (car u) (caddr v)))
(- (* (car u) (cadr v)) (* (car v) (cadr u)))
)
)

(defun transptucs ( pt p1 p2 p3 / ux uy uz )
(setq uz (unit (v^v (mapcar '- p2 p1) (mapcar '- p3 p1))))
(setq ux (unit (mapcar '- p2 p1)))
(setq uy (unit (mapcar '- p3 p1)))

(mxv (list ux uy uz) (mapcar '- pt p1))
)

(defun transptwcs ( pt pt1 pt2 pt3 / pt1n pt2n pt3n )
(setq pt1n (transptucs '(0.0 0.0 0.0) pt1 pt2 pt3))
(setq pt2n (transptucs '(1.0 0.0 0.0) pt1 pt2 pt3))
(setq pt3n (transptucs '(0.0 1.0 0.0) pt1 pt2 pt3))
(transptucs pt pt1n pt2n pt3n)
)

(defun acos ( x )

(if (<= -1.0 x 1.0)

(atan (sqrt (- 1.0 (* x x))) x)

)


)

(setq

TA(GETSTRING "\n ENTER START POINT OF TEXT:");A

TB(GETSTRING "\n ENTER END POINT OF TEXT:");B

TC(GETSTRING "\n ENTER THIRD POINT OF TEXT:");C
)

(setq p1 (getpoint "\n Pick specify start point : "))

(setq p2 (getpoint "\n Pick or specify end point : " p1))

(setq h(getdist p1(STRCAT TA "<----->" TC " LENGTH"))) ;AC

(setq k(getdist p2(STRCAT TB "<----->" TC " LENGTH"))) ;BC

(SETQ
AB(DISTANCE P1 P2)

)

(SETQ

B2(* h h) C2(* AB AB) A2(* k k) CV(* 2 h AB) CB(* 2 k AB) CC(* 2 k h)

ANGA(/(-(+ B2 C2)A2)CV)

ANSA(acos anga);ANGLE A

)

(setq loop t)
(while loop
(setq g (grread t 15 0))
(if (eq (car g) 5)
(progn
(setq p (mapcar '(lambda ( a b ) (/ (+ a b) 2.0)) p1 p2))
;(setq h (/ (distance p1 p2)2 ))
(setq gp (cadr g))
(if (not (minusp (cadr (transptucs gp p1 (polar p1 (angle p1 p2) 1.0) (polar p1 (+ (angle p1 p2) (* 0.5 pi)) 1.0)))))
(progn
(redraw)
(setq p3 (polar p1 ANSA h))
(grdraw p1 p2 1 1)
(grdraw p2 p3 1 1)
(grdraw p3 p1 1 1)
)
(progn
(redraw)
(setq p3 (polar p1 (- ANSA) h))
(grdraw p1 p2 1 1)
(grdraw p2 p3 1 1)
(grdraw p3 p1 1 1)
)
)
)


(progn
(entmake (list '(0 . "LWPOLYLINE") '(100 . "AcDbEntity") '(100 . "AcDbPolyline") '(90 . 3)
(if (eq (getvar 'plinegen) 1) '(70 . 129) '(70 . 1))
(cons 38 (caddr (trans p1 1 (trans '(0.0 0.0 1.0) 1 0 t)))) (cons 10 (list (car (trans p1 1 (trans '(0.0 0.0 1.0) 1 0 t)))
(cadr (trans p1 1 (trans '(0.0 0.0 1.0) 1 0 t))))) (cons 10 (list (car (trans p2 1 (trans '(0.0 0.0 1.0) 1 0 t)))
(cadr (trans p2 1 (trans '(0.0 0.0 1.0) 1 0 t))))) (cons 10 (list (car (trans p3 1 (trans '(0.0 0.0 1.0) 1 0 t)))
(cadr (trans p3 1 (trans '(0.0 0.0 1.0) 1 0 t))))) (cons 210 (trans '(0.0 0.0 1.0) 1 0 t))))
(setq loop nil)
)


)
)

(redraw)

(SETQ
;di (/ (* *ht* 0.45) 0.5)
nm (TRANS '(0.0 0.0 1.0) 1 0 T)
a (ANGLE p1 p2)
b (rtos(distance p1 p2)2 2) ;distance p1 p2
c (STRCAT"("b")") ;final answer with () bracket add of distance p1 p2

)


(ENTMAKE (LIST (CONS 0 "TEXT")
(CONS 100 "AcDbEntity")
(CONS 100 "AcDbText")
(CONS 10 (LIST 0. 0. 0.))
(CONS 40 😎
(CONS 7 (GETVAR 'textstyle))
(CONS 8 "Some layer")
(CONS 62 1)
(CONS 1 c) ;text value of p1 to p3 distance
(CONS 50
(IF (MINUSP (COS a))
(+ PI a)
a
)
)
(CONS 72 1) ; all three cons justification of text
(CONS 11 (LIST (/ (+ (CAR p1) (CAR p2)) 2.0) (/ (+ (CADR p1) (CADR p2)) 2.0) 0.0))
(CONS 73 1)
)
)

(setq
d(ANGLE p1 p3)
e(rtos(distance p1 p3)2 2) ;distance p1 p3
f(STRCAT"("e")") ;final answer with () bracket add of distance p1 p3
)

(ENTMAKE (LIST (CONS 0 "TEXT")
(CONS 100 "AcDbEntity")
(CONS 100 "AcDbText")
(CONS 10 (LIST 0. 0. 0.))
(CONS 40 😎
(CONS 7 (GETVAR 'textstyle))
(CONS 8 "Some layer")
(CONS 62 1)
(CONS 1 f) ;text value of p1 to p3 distance
(CONS 50
(IF (MINUSP (COS d))
(+ PI d)
d
)
)
(CONS 72 1) ; all three cons justification of text
(CONS 11 (LIST (/ (+ (CAR p1) (CAR p3)) 2.0) (/ (+ (CADR p1) (CADR p3)) 2.0) 0.0))
(CONS 73 1)
)
)

(setq
g(ANGLE p2 p3)
h(rtos(distance p2 p3)2 2) ;distance p2 p3
i(STRCAT"("h")") ;final answer with () bracket add of distance p2 p3
)

(ENTMAKE (LIST (CONS 0 "TEXT")
(CONS 100 "AcDbEntity")
(CONS 100 "AcDbText")
(CONS 10 (LIST 0. 0. 0.))
(CONS 40 😎
(CONS 7 (GETVAR 'textstyle))
(CONS 8 "Some layer")
(CONS 62 1)
(CONS 1 i) ;text value of p2 to p3 distance
(CONS 50
(IF (MINUSP (COS g))
(+ PI g)
g
)
)
(CONS 72 1) ; all three cons justification of text
(CONS 11 (LIST (/ (+ (CAR p2) (CAR p3)) 2.0) (/ (+ (CADR p2) (CADR p3)) 2.0) 0.0))
(CONS 73 1)
)
)

(command "text" "j" "bc" p1 8 0 TA "" "")
(command "text" "j" "bc" p2 8 0 TB "" "")
(command "text" "j" "bc" p3 8 0 TC "" "")

)

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

0 Likes
564 Views
5 Replies
Replies (5)
Message 2 of 6

john.uhden
Mentor
Mentor

@jaimuthu ,

Sorry, but I am having a hard time figuring out your procedure.

Is each triangle created as a polyline?

If so, then you must determine the direction of the polyline, CW or CCW, and put your text to the inside based on the fact that "inside" means to the left (CCW) of any segment and vice versa.

If all the sides are just lines, then I think you would have to create additional functions to determine the direction.

Hopefully others much wiser than myself will respond with better solutions.

John F. Uhden

0 Likes
Message 3 of 6

Kent1Cooper
Consultant
Consultant

@jaimuthu wrote:

....

4) I run program TRI command for T2 Triangle Change in UCS "3" Point method T2 Triangle shape is correct distance ,But text value is Outside of object

....

(CONS 72 1) ; all three cons justification of text
(CONS 11 (LIST (/ (+ (CAR p2) (CAR p3)) 2.0) (/ (+ (CADR p2) (CADR p3)) 2.0) 0.0))
(CONS 73 1)

....


For that, I think [untested -- the code has emoticon pollution] that you probably need to apply some (trans) functions to convert the insertion points of the Text objects from the current UCS [which is what (getpoint) returns in] to the WCS [which is what (entmake) must use].  Perhaps something like:

....

  (CONS 72 1) ; all three cons justification of text
  (CONS 11 (trans (LIST (/ (+ (CAR p1) (CAR p3)) 2.0) (/ (+ (CADR p1) (CADR p3)) 2.0) 0.0) 1 0))
  (CONS 73 1)

....

and probably also something similar for the rotation angles, perhaps [I'm not as familiar with using it for angles] involving the disp argument in (trans) [>read about it<].

Kent Cooper, AIA
0 Likes
Message 4 of 6

Sea-Haven
Mentor
Mentor

Was looking for a point Z inside a triangle and found lots of formula reference for point inside a triangle. Just google it. It is formulas not code. 

 

Maybe this simple solution. This should work for triangles that are not in Z direction only.

 

SeaHaven_0-1687926397509.png

 

Message 5 of 6

john.uhden
Mentor
Mentor

@Sea-Haven ,

Never thought of comparing areas.

Except it gets a little more complicated when when an outside segment is bulged.

John F. Uhden

0 Likes
Message 6 of 6

komondormrex
Mentor
Mentor

could you show a close-up of this one?

 

komondormrex_0-1688124818118.png

 

0 Likes