Welcome to the Onshape forum! Ask questions and join in the discussions about everything Onshape.
First time visiting? Here are some places to start:- Looking for a certain topic? Check out the categories filter or use Search (upper right).
- Need support? Ask a question to our Community Support category.
- Please submit support tickets for bugs but you can request improvements in the Product Feedback category.
- Be respectful, on topic and if you see a problem, Flag it.
If you would like to contact our Community Manager personally, feel free to send a private message or an email.
Get a Vector from an Edge
Alex_Pitt
Member Posts: 65 PRO
Is there a way to convert an edge (query) to a vector?
I've asked Chat GPT but it just seems to make stuff up...
"Hi, Chat GPT here,
In Onshape FeatureScript, you can convert an edge to a vector using the
I've asked Chat GPT but it just seems to make stuff up...
"Hi, Chat GPT here,
In Onshape FeatureScript, you can convert an edge to a vector using the
opEdgeToVector
function. This function takes an edge as input and returns a vector representing the direction of the edge.Here's a simple example demonstrating how to use opEdgeToVector
:
javascriptCopy codeimport(path : "onshape/std/geometry.fs", version : "252.0");
// Define a simple edge
const edge = edge(context, {
start: vector(0, 0, 0),
end: vector(1, 1, 1)
});
// Convert the edge to a vector
const edgeVector = opEdgeToVector(edge);
// Print the result
println("Edge vector: ", edgeVector);
This script creates a simple edge from the point (0, 0, 0) to the point (1, 1, 1), then converts this edge to a vector using opEdgeToVector
, and finally prints the resulting vector..."
Tagged:
0
Best Answer
-
NeilCooke Moderator, Onshape Employees Posts: 5,688You got it.Senior Director, Technical Services, EMEAI0
Answers
I'm not up to speed enough for the help to mean much... evEdgeTangentLine(context, map) returns line. If this will somehow return a vector from an edge query I will investigate further.
Re tutorials, I did the Fundamentals course a few years ago which is very good but I'll need to revisit. I'll keep plugging away. I'm sure it will twig in time.
var myLine is Line = evEdgeTangentLine(context, {
The debug looks like this.
debug: Line direction (-0, -0, -1)
I can now get the length of my edge. (0.3m) by multiplying the respective components of the Line direction unit vector (-0, -0, -1) and the myLine vector (0.1m,0m,0.3m).
Seems a very convoluted way to do it though.
I'm unsure how to get the unit vector so I'll have a look through the help. Maybe one of the evaluate functions...
A "Line" is a special kind of "map" is that right? Direction + Point. Infinite length.
Unsure how to isolate the "direction" component of that "Line".
Looking to the help...
"...Map elements are accessed or changed using the map key. If the map key is a string that is a valid identifier, dot syntax may be used.
myLine.direction ?
Thanks Neil & Greg.
});