- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Understanding Vector2D and UnitVector2D
Hello,
I have a problem understanding how to use vectors in a sketch.
Situation:
My code creates a sketch in sheetmetals, projects the edges and then offsets those lines.
Currently, I want to make a centermark pattern on the offseted lines.
As a mechanical engineer, for me, a vector has a direction and a magnitude
But when you do transientGeometry.CreateVector2d then you have to fill in X and Y coords.
My brain says with that input you get a point, not a vector
And if i search in:
Dim vec as vector2d
you can find: vec.length
How does the vector get length from that input
Or is this perhaps an array of 2 x points and 2 y points? (but how is that done)
Also what is UnitVector2d compared to vector2d
I got weird results and I'm obviously missing some basics.
Help
So imagine what I want to create:
I have a sketchline, with any angle, and any length (But its always a straight line, no arc entities etc)
Based on the length of the line I determine how many holes, distance between holes and distance from edges. (got that working)
Then i want to create sketchpoints, measured from the startpoint of the sketchline in the direction of the sketchline (im stuck here)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi @Cadkunde.nl. Some transient geometry objects in Inventor can definitely be challenging to get your head around. Attached is an old PDF from a class in Autodesk University some number of years ago, and it is pretty nice at describing some of those types of things. The Vector2d and UnitVector2d are the same in every aspect except 'length'/magnitude. The Vector2d's length can be any length, but the UnitVector's length will always be 1 unit, because the UnitVector2D's only use is for specifying direction, not distance (such as for a coordinate system's axis directions). The point coordinates that you either input, or get back from them can be understood this way... A line is drawn from the origin 0,0 point to those coordinates. That line has a direction and length. That is how to see the 'line' type geometry in your head.
Wesley Crihfield
(Not an Autodesk Employee)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
As for the task of creating a series of SketchPoints along a SketchLine... When creating a SketchPoint, it want a Point2D as input. We can get some data like that from digging down a few levels under the SketchLine's properties. The SketchLine.Geometry property returns a LineSegment2D object. This has the 3 expected properties for start, mid, and end points, but we can dig into its LineSegment2D.Evaluator property to get the Curve2DEvaluator object, which has a lot of nice methods available for more detailed analysis/data. We can use its GetParamExtents to get its Min & Max parameters. To use that, you must first create the two Double type variables, with no values set to them yet, then supply those to that method, and the method will fill in their values, and you can use those variables later for certain things. Now it depends on how you want to specify the locations of the SketchPoints as to which methods we need to use next. If we used the GetLengthAtParam method, and used those two variables as the first two inputs, it would return the length of the entire SketchLine, but we don't need that, because that was available at a higher level. Usually by param, they mean a Double representing a percentage of a length, like .5 being equal to 50%. If we use the GetParamAtLength method, we could use the Min variable as the first input, then a Length for the second input, then the third input would be a pre-declared Double type variable that the method would set the value of to the parameter (percentage) that point along the entity is at. If we used the GetPointAtParam method, I believe the first input variable (an Array of Double) would be 1 or more params (percentages along the entity), and the other input variable (also an Array of Double) would be set to the sets of 2D point coordinates for each point at the specified parameters. But I haven't used that one in a while, so I'm a little rusty.
Wesley Crihfield
(Not an Autodesk Employee)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Thx.
I read that rabbithole article. But thats about the only thing about vertex. And an example in programming help moving something with vertex(5,0) still cant solve my issue.
If you have a sketchline. Not starting at 0 and not horizontal or vertical. I have startpoint and endpoint geometry as point2d.
How do I make a centerpoint lets say 50mm from the startpoint in the direction of the line.
A simple code example
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
This is what I was working on:
Dim Length As Double = firstLine.StartSketchPoint.Geometry.DistanceTo(lastLine.StartSketchPoint.Geometry)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Solved it with a test in ilogic.
Still wonder if this is the best way to do it.
I get the direction from line.geometry.direction
This is a unitvector which has length value = 1
I cast it AsVector and then I scale it by 5 and i get 50mm
Dim odoc As PartDocument = ThisDoc.Document Dim osketch As PlanarSketch = odoc.ComponentDefinition.Sketches.Item(1) Dim line As Inventor.SketchLine = osketch.SketchLines(1) Dim osel As Inventor.SelectSet = odoc.SelectSet Dim opoint As Inventor.SketchPoint = line.StartSketchPoint Dim vec As Inventor.Vector2d = line.Geometry.Direction.AsVector vec.ScaleBy(5) Dim tg As TransientGeometry = ThisApplication.TransientGeometry Dim holepoint2d As Inventor.Point2d = tg.CreatePoint2d(opoint.Geometry.x+vec.X, opoint.Geometry.y+vec.Y) Dim skpnt As SketchPoint = osketch.SketchPoints.Add(holepoint2d, True)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I know you already figured something out, but is another very similar example iLogic rule for that same task, just as another idea. It just does a couple things slightly differently, avoiding the need for math, but I used a 'less than one' ratio, as a percentage of the line's length or the point's location, instead of 5x, so that the point would be within the line's geometry. This worked as expected for me too.
Dim oPDoc As PartDocument = ThisDoc.Document
Dim oSketch As PlanarSketch = oPDoc.ComponentDefinition.Sketches.Item(1)
Dim oSLine As SketchLine = oSketch.SketchLines.Item(1)
Dim oP2D As Point2d = oSLine.StartSketchPoint.Geometry.Copy
Dim oV2D As Vector2d = oP2D.VectorTo(oSLine.EndSketchPoint.Geometry)
oV2D.ScaleBy(0.25)
oP2D.TranslateBy(oV2D)
Dim oSPoint As SketchPoint = oSketch.SketchPoints.Add(oP2D, True)
Wesley Crihfield
(Not an Autodesk Employee)