How draw a line without draw edge?

I wish to find distance between a point (pt0) and a line that include 2 points (pt1 and pt2). Following codes can do it.

edge = Sketchup.active_model.entities.add_line(pt1, pt2)
line1 = edge.line
edge.erase!
dis = pt0.distance_to_line(line1)

I have to do it inside “onMouseMove” definition. Drawing edge and delete it cause view will be slow. Is it possible to draw line1 without drawing and deleting edge?

“draw” is literally not possible, because a line is an abstract thing in SU. But you can “describe” it.

A line can be represented as either an Array of a point and a vector,
or as an Array of two points.

See: Module: Geom

Therefor the line could be:

line1 = [pt1, pt2]
#or
line1 = [pt2, pt1]

or could be

line1 = [pt1, pt1.vector_to(pt2)]
#or 
line1 = [pt2, pt1.vector_to(pt2)]
#or 
line1 = [pt2, pt2.vector_to(pt1)]
#…and so on.


Your code can be one (text) line:

dis = pt0.distance_to_line([pt1, pt2])
3 Likes

Thank you so much Dezmo, I really like all in one line.

angle = (vector1.angle_between vector2).radians

It measure angle. How I know angle is positive or negative? Vector1 rotate CW to match to vector2 or ACW?
Thank you in advance

Sorry to bother you. I used “vector3 = vector1 * vector2” and polarity of “vector3.z” solved my problem. Thanks again.