I meet a problem when I am programming with rhinoscriptsyntax.Basically, I need to offset a curve to the direction that contrary to it (like the picture show). But when I use the OffsetCurve command, I find out that the ‘direction’ parameter, which inputed as a point or a Vector3D, can not adjust the direction of the offset. In this case, I use (0, -1, 0) as a direction, but it still points in the positive direction of the y-axis. The only that I can control the direction is to use the positive and negative values of distance.
My question is: How to control the orientation of offset with a vector or point, but not positive and negative of numbers.
That is my first forum of this forum, I sincerely ask the experts for help😊
Here is the script
import rhinoscriptsyntax as rs
base_line = rs.AddLine(rs.AddPoint((1, 10, 0)), rs.AddPoint((10, 10, 0)))
offseted_line_1 = rs.OffsetCurve(base_line, (0, 1, 0), 2)
'''
I wanna use "vector" as a direction vector or point to describe the 'Y-axis positive direction'
While, it not work, the direction of offset can only be controled by the positive and negative of "distance"
I trying to convert a point to a vector, and received a similar result
'''
vector = rs.VectorCreate((0, 0, 0), (0, 1, 0))
offseted_line_2 = rs.OffsetCurve(base_line, vector, 2)
Maybe something like this?
import rhinoscriptsyntax as rs
#create start and end points
s_pt=rs.coerce3dpoint([1,10,0])
e_pt=rs.coerce3dpoint([10,10,0])
#add line
base_line = rs.AddLine(s_pt,e_pt)
#create a world +Y vector
y_vec=rs.coerce3dvector([0,1,0])
#add the vector to line mid point to create offset point
offset_pt=rs.CurveMidPoint(base_line)+y_vec
#offset the line
offset_line_1 = rs.OffsetCurve(base_line, offset_pt, 2)
rs.OffsetCurve()
only takes a point for the offset direction, not a vector. In Rhino/Python you can add a vector to a point to create another point displaced by the vector distance and direction.
It works! Thanks for your help. It seems that I misunderstood the ‘direction’ parameter.
Additionally, I want to ask that I do not find the ‘coerce3dvector’ command in the rhinoscriptsyntax document. And I also notice that it return Rhino.Geometry type object and do not write by Camel Case. Is this the command to use rhinoscriptsyntax to call rhino command? And how you look at this kind of method. I’m confused because I’ve never used this kind of function before in rhinoscriptsyntax.
Sorry for the late answer, I was out all day today.
Yes, the ‘coerce…’ functions were originally created as utility functions for internal use and as such were not exposed to the general users. In the script editor, if you type rs.coerce
the autocomplete will show you all of the functions available. Basically their function is to try to create the desired geometrical object from various possible inputs.
You could also use rs.VectorCreate() but that requires 2 points, whereas the coerce3dvector() creates a vector directly with the single triple numerical input. You could also use RhinoCommon (import Rhino
) and create a vector directly with vector=Rhino.Geometry.Vector3d(x,y,z)
Vectors can also be created by subtracting one 3dPoint from another, i.e. ptB-ptA
creates the vector from point A to point B.
Thank you for your complete and detailed answer