PDA

View Full Version : Open source geometry stuff



MetLHead
08-26-2005, 06:51 PM
One of the biggest hurdles, I think, to writing any kind of CAD/CAM app is going to be getting a handle on the geometry involved. I'm going to contribute a Visual Basic module which contains 26 different geometry functions. This module contains only 2D functions, but could easily be adapted for 3D. I'm putting this up here so that hopefully someone will find it useful. If anyone wants to add to it or update it, that's great. Just make sure and re-post it here so that others can benefit too.

Scott

Evodyne
08-26-2005, 07:50 PM
Scott,

Good Job! Thanks for the contribution. What have you done with this yourself?

Sincerely,

Lance/Evodyne

MetLHead
08-26-2005, 08:12 PM
This module is taken right out of NCPlot. Of course, NCPlot contains a lot more stuff... I can't give away everything!

Here's a good challenge that would be a great addition to an open source project:
Add cutter comp functions
Create pocketing routines

Okay, so that's two challenges, but I think both could be done using the building blocks provided by this module.

Scott

Honges
10-19-2007, 02:02 PM
Hi Scott,
thanks !!
These routines are exactly what I needed.
I had cold sweat running down my neck when thinking of reanimating my geometrical school knowledge :-)))
Best regards Honges

carbo20
06-15-2010, 08:18 AM
Thank you very much! it is very helpful library.
the only thing that i can't find anywhere is a function that receive 2 lines (2 points that defines each line) and a radius. the function returns the points of tangency.
it is for a fillet feature that I'm trying to build in vb.

_Eduardo_
06-20-2010, 01:34 AM
Try something like this:

Notes:
- The endpoint of Line1 must be the startpoint of Line2. (<-- EDIT: Is not the same, it's the startpoint :) )

- The input is Line1,Line2 and Radius.R
- Return: Fill Radius with the rest of parameters (Radius.S,Radius.E,Radius.C,Radius.D)


(coypaste of the user types)

Type dPoint
X As Double
Y As Double
End Type

Type dLine
S As dPoint 'Start Point
E As dPoint 'End Point
End Type

Type dArc
S As dPoint 'Arc Start Point
E As dPoint 'Arc End Point
C As dPoint 'Arc Center Point
R As Double 'Arc Radius
D As Integer 'Arc Direction (2=CW, 3=CCW)
End Type


Public Sub GetRadiusParms(Line1 As dLine, Line2 As dLine, Radius As dArc)
Dim D1u As dPoint
Dim D2u As dPoint
Dim rs As Double
Dim q As Double

D1u.X = Line1.E.X - Line1.S.X
D1u.Y = Line1.E.Y - Line1.S.Y
q = Sqr(D1u.X ^ 2 + D1u.Y ^ 2)
D1u.X = D1u.X / q
D1u.Y = D1u.Y / q

D2u.X = Line2.E.X - Line2.S.X
D2u.Y = Line2.E.Y - Line2.S.Y
q = Sqr(D2u.X ^ 2 + D2u.Y ^ 2)
D2u.X = D2u.X / q
D2u.Y = D2u.Y / q

q = Radius.R * (D1u.X * D2u.Y - D1u.Y * D2u.X) / (1 + D1u.X * D2u.X + D1u.Y * D2u.Y)
If q < 0 Then
rs = -Radius.R
Radius.D = 2
q = -q
Else
rs = Radius.R
Radius.D = 3
End If

Radius.S.X = Line1.E.X - q * D1u.X
Radius.S.Y = Line1.E.Y - q * D1u.Y
Radius.E.X = Line1.E.X + q * D2u.X
Radius.E.Y = Line1.E.Y + q * D2u.Y

Radius.C.X = Radius.S.X - rs * D1u.Y
Radius.C.Y = Radius.S.Y + rs * D1u.X

End Sub


Sorry for the lack of comments :)

Good luck!

carbo20
06-20-2010, 03:02 AM
Thank you very much.
I will try it.

carbo20
07-07-2010, 05:44 AM
It works!
Thank you.

I will explain my motivation:
I'm trying to draw the data from your code to the screen (and then to a file) .
I need to use only points (every 2 points i draw as a line on the screen - so i will be able to see what i am going to cut. my diamond turning cnc can only accepts points files).
I'm using the circle equation to find the z for each x (i'm using your points as start point for the fillet.
right now the only thing that works properly is your code :)