Help adding arc in ruby script
-
I am currently working on a mortise tool script based on the dado tool of Woodwrk.rb and it is working fine for square end mortise but I also want to add the capability of round mortise that is made with a router.
This is the final section of the script that draws the mortise:
po1=pt1.transform(backt) #Typical results (3.75,-0.5,0) po4=pt4.transform(backt) #Typical results (3.75,-0.25,0) po2=pt2.transform(backt) #Typical results (0.25,-0.5,0) po3=pt3.transform(backt) #Typical results (0.25,-0.25,0) codef=@entity.definition cface=codef.entities.add_face po1,po2,po3,po4 h=-1*@@depth cface.pushpull h Sketchup.active_model.commit_operationWhat I need to do is add a curve (half circle) that connects p1 to p4 and p2 to p3
From the SU I see that this is the type of code that is needed and I know the centerpoints
radius but am not sure of the start and end vectors etc.# Create a circle perpendicular to the normal or Z axis vector = Geom;;Vector3d.new 0,0,1 vector2 = Geom;;Vector3d.new 1,0,0 vector3 = vector.normalize! model = Sketchup.active_model entities = model.active_entities arccurve = entities.add_arc centerpoint, vector2, vector3, 10, 15, 35 UI.messagebox arccurveYour help would be appreciated
Keith -
The start/end vectors are those from the
centerpointto the start/end points of the arc.
You have those points, sovec_start=start_point-centerpointandvec_end=end_point-centerpointwill give these vectors.
You need to know which end is which so that the required part of the arc gets drawn... -
TIG if I am reading your post correctly I define the vectors as shown?
vec_start=po1-centerpoint
vec_end=po4-centerpointSecond question will the following statement pick the face that includes the radius on the ends between point1 and point4?
cface=codef.entities.add_face po1,po2,po3,po4
Thanks for your help
Keith -
@ktkoh said:
Second question will the following statement pick the face that includes the radius on the ends between point1 and point4?
cface=codef.entities.add_face po1,po2,po3,po4
That won't pick a face. It will create a new one. But it will return the newly created face.
-
arcs are not easy! ....here are some code sippits from a a ruby of mine, I hope this helps!
x=0 y=0 z=0 pi = 3.141592653589793 # 180 degree angle = pi radians vecz = Geom;;Vector3d.new(0, 0, 1) vecy = Geom;;Vector3d.new(0, 1, 0) vecx = Geom;;Vector3d.new(1, 0, 0) # the 4 quadrants of a circle; are # # pi, pi/2 | 0,pi/2 # ---------+-------- # -pi/2,-pi | -pi/2,0 # # the following, is an example using an arc statement incorporating the above definitions # this arc is 90 degress, and lies in the 2nd quadrant # model.entities.add_arc([x+@dist, y+@dist, z], vecx, vecz, @d/2, 0, pi/2, @s) # -
It's often forgotten that you can specify angles in Ruby Sketchup in degrees directly, thus
angle=180.degrees- no need to muddle on with PI and radians ! -
tomot:
No need to define pi yourself as a variable. (first of all it'd make more sense to defined it as a constant)
But you have it already define in the math module:Math::PIAnd you don't have to calculate the radian values yourself. The Numeric class has
.degreesand.radiansto do that for you. http://code.google.com/apis/sketchup/docs/ourdoc/numeric.htmlmodel.entities.add_arc([x+@dist, y+@dist, z], vecx, vecz, @d/2, 0, 90.degrees, @s)(whoop! TIG beat me to it... Except the PI part.)
-
hi,
is it also possible to draw a 3-point-arc in ruby? without defining a center?i want to ad an arc along an edge, so the points would be (when edge is in y-direction):
arc_1 = 0,0,0
arc_2 = 0,y,0
arc_3 = x,y/2,0is there a way?
thanx stan
-
@artmusicstudio said:
hi,
is it also possible to draw a 3-point-arc in ruby? without defining a center?i want to ad an arc along an edge, so the points would be (when edge is in y-direction):
arc_1 = 0,0,0
arc_2 = 0,y,0
arc_3 = x,y/2,0is there a way?
thanx stan
Yes of course, but it needs some trigonometry...
Find my 'Arc_By...' tools in the PluginsStore and see the RB inside the RBZ archive.
The RB include algorithms for making arcs in many ways... -
hi tig, ok,
let's play with some formulas
thanx stan
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better π
Register LoginAdvertisement