×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Best Fit line
2

Best Fit line

Best Fit line

(OP)
Dear All,

I'm a new catia user and would have a question for you.

I'm using a mesuring device that produce a set of points in catia.

Does anyone knows a way to trace a best fit line through those points? (like linear regression ).

Thank you in advance for your help.

RE: Best Fit line

In my opinion You need to use a macro that calculate line equation from given points

You need to use method "GetCoordinates" (Member of HybridShapeTypeLib.Point)

Is it Yours school project or You need this for commercial use?

If You are interested in Macros in Catia (Catscripts, Catvba) feel free to send me a message. I will wrote specified macros for free and post it on eng-tips forum

RE: Best Fit line

CODE --> catvba

Sub CATMain()

Set ParttDocument1 = CATIA.ActiveDocument
Dim Coord(2)

Set selection1 = ParttDocument1.Selection
PointName = selection1.Item(1).Reference.Name
HybridBodyName = selection1.Item(1).Reference.Parent.Parent.Name
ParttDocument1.Part.HybridBodies.Item(HybridBodyName).HybridShapes.Item(PointName).GetCoordinates Coord

MsgBox " Coordinates  X:" & Coord(0) & "   Y:" & Coord(1) & "   Z:" & Coord(2)
End Sub 

Here is a simple code to get coordinates from selected points
You can replace lines:

CODE -->

PointName = selection1.Item(1).Reference.Name
HybridBodyName = selection1.Item(1).Reference.Parent.Parent.Name
ParttDocument1.Part.HybridBodies.Item(HybridBodyName).HybridShapes.Item(PointName).GetCoordinates Coord 

by this one:

CODE -->

selection1.Item(1).Value.GetCoordinates Coord 
It would help to avoid problems with points or geometrical sets with the same names

Lukasz

If You are interested in Macros in Catia (Catscripts, Catvba) feel free to send me a message. I will wrote specified macros for free and post it on eng-tips forum

RE: Best Fit line

(OP)
Thanks a lot Lukaszsz for you help.

Your macro works just fine. I have some background in programming in C and Java but none in vbs.

I know i need to create a Type for coord
Then a array of my new type
Collect all the coord in my array.

I tried a bit but without proper knowledge of vbs, i couldnt succeed.

Writing the routine to best fit a line given the coordinates of point shouldnt be a problem.

RE: Best Fit line

Quote:

Writing the routine to best fit a line given the coordinates of point shouldnt be a problem.

Not in 2-D, but in 3-Dimensional space Line is referenced by 6 variables, 2 planes intersection (2x3variables) or vector[x,y,z] and passing point (xa,ya,za).

to create array dimensioned as below [number of points, coordinates] try to use this script:

CODE -->

Sub CATMain()

Set PartDocument1 = CATIA.ActiveDocument
Set selection1 = PartDocument1.Selection
Dim Coord(2)
Dim Crd() As Variant

ReDim Crd(selection1.Count - 1, 2)


For i = 1 To selection1.Count
selection1.Item(i).Value.GetCoordinates Coord
Crd(i - 1, 0) = Coord(0)
Crd(i - 1, 1) = Coord(1)
Crd(i - 1, 2) = Coord(2)
MsgBox " Coordinates of point No: " & i & Chr(10) & " X:" & Crd(i - 1, 0) & "   Y:" & Crd(i - 1, 1) & "   Z:" & Crd(i - 1, 2)
Next i
End Sub 

If You are interested in Macros in Catia (Catscripts, Catvba) feel free to send me a message. I will wrote specified macros for free and post it on eng-tips forum

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources