Def help!
-
The following definition statement has been an invaluable time saver for me
when I scripted my WindowTools and DoorTools rubies. Its never to late to thank Didier for writing it a long time ago, when I found it in one of his scripts.# creates a new point from p1 in the direction of p2-p3 with length d # params are Point3d, 2 vertices, a length, returns a Point3d def translate(p1, p2, p3, d) v = p3 - p2 v.length = d trans=Geom;;Transformation.translation(v) return p1.transform(trans) end
I'm wondering if its possible to someone here to help construct a similar time saver definition for the following statements, I lack some fundamental ruby programming skills to create such a definition.
#------Computer new point pt11, $width (6") and at the same angle plus 90 degrees from pt1 vec = @ip2.position - $pt1 ang = 1.5707963267948965 vec.length = $width # $width of wall (6") translate = Geom;;Transformation.translation(vec) rotate = Geom;;Transformation.rotation( $pt1, Geom;;Vector3d.new(0, 1, 0), ang) trans = $pt1.transform(translate) $pt11 = trans.transform(rotate)
It seems like a lot of work to go on repeating this code snippet 20 more times to find 20 additional points.
BTW: It should be observed that the same scripted in the AutoLisp for AutoCad involved the following single statement:(setq pt3 (polar pt1 (+ ang (dtr 90)) 6))
-
Try this:
def method_name(pt1, pt2, width) vec = pt2 - pt1 ang = 90.degrees rotate = Geom;;Transformation.rotation( pt1, Geom;;Vector3d.new(0, 1, 0), ang) vec = vec.transform(rotate) pt11 = pt1.offset(vec, width) end
-
What will be the name of the this method?
-
I think if you explained in 'words' not pseudo-code what you want to do then suggestions would be more forthcoming...
Kyyu's suggested method takes arguments of two points and a 'width'; it gets the vector between the points, it then transforms the vector by rotating about the Y_AXIS by 90 degrees, and then moving a clone of the first point along the adjusted vector by 'width'. This new point is returned by the method. This seems a very specific 'tool' and could be made far more general - e.g. by passing an angle too...
What is it you want these methods to 'do' for you ? ... -
@tig said:
I think if you explained in 'words' not pseudo-code what you want to do then suggestions would be more forthcoming...
Kyyu's suggested method takes arguments of two points and a 'width'; it gets the vector between the points, it then transforms the vector by rotating about the Y_AXIS by 90 degrees, and then moving a clone of the first point along the adjusted vector by 'width'. This new point is returned by the method. This seems a very specific 'tool' and could be made far more general - e.g. by passing an angle too...
What is it you want these methods to 'do' for you ? ...Thanks for your comments: Your description precisely describes what this method is supposed to do. Its not really all that specific. As I commented above its the typical way an Autolisp routine works, when one is defining points one after the other. In Autolisp Its called polar - derive point from angle and distance function, without it you would not be able to do 80 percent of the stuff involving angles. Sadly the Ruby API dose not include robust code dealing with angles, or arcs.
-
Advertisement