Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > General > Math for Creating Offset for Lines/Shapes


Reply
 
Thread Tools Display Modes
  #1  
Old 08-06-2008, 10:42 PM
arunkish arunkish is offline
Newcomer
 
Join Date: Aug 2008
Posts: 18
Question Math for Creating Offset for Lines/Shapes


Finally, I hope that I'm in the right place for getting some solution for my problem. I have a VB 6.0 program that uses VECAD Activex for creating some shapes using lines, splines, arc etc.... In the OCX I'm able to retrive the Left,Right,Top and Bottom of the every shapes. i.e x,y... . All I would like to do is to create an offset for the shapes. i.e In the shape if i do click a single object it has to create an offset line. i.e the created offset has to line outside the whole object. Simply to tell. Like creating borders for the whole object or an outline. Hope u are clear. Please advise me on this.
Reply With Quote
  #2  
Old 08-06-2008, 11:33 PM
NEOLLE's Avatar
NEOLLE NEOLLE is offline
fully realized avatar

Super Moderator
* Expert *
 
Join Date: Jun 2004
Location: Davao Philippines
Posts: 2,295
Default

Hello arunkish and welcome to the forum!

In AutoCAD, we use the Offset function. Perhaps there is one also in Vecad...
Reply With Quote
  #3  
Old 08-07-2008, 02:08 AM
arunkish arunkish is offline
Newcomer
 
Join Date: Aug 2008
Posts: 18
Default

Vecad???? I dont think so. I searched for the help. But no such thing. Sorry if I'm wrong. If it is... can u please give me an example source???
Reply With Quote
  #4  
Old 08-07-2008, 02:09 AM
arunkish arunkish is offline
Newcomer
 
Join Date: Aug 2008
Posts: 18
Default

I tired Vecad.. But I dont really think that the offset thing is available. That's why I tried to workout manually. Please help.
Reply With Quote
  #5  
Old 08-07-2008, 09:59 AM
Gruff's Avatar
Gruff Gruff is offline
Bald Mountain Survivor

Super Moderator
* Expert *
 
Join Date: Aug 2003
Location: Oregon, USA
Posts: 5,879
Default

Quote:
All I would like to do
Sometimes an answer is not as simple as we would like it to be.

Is see three major hurdles.

1)As mkaras points out it is much more difficult to generate parallel conics and splines. I wrote code to do that sort of thing back the 80's. I doubt I have it anymore. (Though you might be able to find it by searching old Cadkey forums. Look for a parallel spline tool. (2D cubic parametric splines)

2) As I suspect your "shapes" are 2D wireframe in nature. Determining the the outside vector of your shape will be a bigger problem. In most CAD applications you have to give the parallel entity creation tool a hint as to which side of the source entity to use to create the parallel entity. (User clicks the mouse pointer beside the line.)

Because of this I doubt your program will be able to do the job automatically. Especially if your shapes are complex. (Beyond circular or polygon.)

3) When creating parallel profiles sometimes a fillet radius will fall below 0. The arc will need to be removed entirely and the ajoining entities will need to be extended to fill the gap. This is just one of several geometry failures that can happen when working with vectors shapes.

Regarding 2) You can use the following sample snippet to determine whether an end point in inside or outside a "Simple " closed shape.

Code:
'Public Type CAD_Point ' X as Double ' Y as Double 'End Type Function IsInPolygon(ByVal TotalPoints As Integer, _ ByRef Points() As CAD_Point, _ ByVal x As Double, ByVal y As Double) As Boolean Dim InSide As Boolean Dim i As Integer, j As Integer i = 0 j = TotalPoints - 1 InSide = False For i = 0 To TotalPoints - 1 If ((((Points(i).y <= y) And (y < Points(j).y)) Or _ ((Points(j).y <= y) And (y < Points(i).y)))) Then If (x < (Points(j).x - Points(i).x) * (y - Points(i).y) / _ (Points(j).y - Points(i).y) + Points(i).x) Then InSide = Not (InSide) End If End If j = i Next i IsInPolygon = InSide End Function


~T
__________________
Burn the land and boil the sea
You can't take the sky from me


~T

Last edited by Gruff; 08-07-2008 at 10:29 AM.
Reply With Quote
  #6  
Old 08-07-2008, 09:56 PM
arunkish arunkish is offline
Newcomer
 
Join Date: Aug 2008
Posts: 18
Default

Dear Mkaras and Gruff,

Thank you for your code and advise. But I dont get how do I use the Code what Gruff had given and exactly how the what has to be passed to it. I have attached a zip file that contains a word document, that clearly explains the problem. Please let me know if you have any difficulties. I have prepared it to explain you exactly how my shape will be and the values that I may retrive.....

Gruff.... Does your code works like this???? I have to click the line for which I have create the offset and click somewhere outside the shape. The function will return if I had clicked outside or Inside. Right?

Thanks in advance.

Last edited by Gruff; 08-08-2008 at 11:52 AM.
Reply With Quote
  #7  
Old 08-08-2008, 11:56 AM
Gruff's Avatar
Gruff Gruff is offline
Bald Mountain Survivor

Super Moderator
* Expert *
 
Join Date: Aug 2003
Location: Oregon, USA
Posts: 5,879
Default

I removed your Word Doc. Post RTF format attachments instead. This is a forum policy.

1) Your example shows only lines. Is that the only entity type you want to make a parallel for?
2) Is having your program user select a point beside a line acceptable?

The code I posted will determine if a point is inside or outside a polygon. That is all it does.

If items 1 and 2 above are true I might be able to help you with the code.
I am leery of doing so though because you say you do not understand how to use the function I posted before.

CAD is complex. Going forward with your request is not going to get simpler.
__________________
Burn the land and boil the sea
You can't take the sky from me


~T

Last edited by Gruff; 08-08-2008 at 12:08 PM.
Reply With Quote
  #8  
Old 08-08-2008, 09:29 PM
arunkish arunkish is offline
Newcomer
 
Join Date: Aug 2008
Posts: 18
Default

Dear Gruff....

I'm sorry. I think u have misunderstood in what I meant about. I was bit confused on thinking how I can use your code for my application. But anyhow sorry if I was wrong.

I'm having difficulties as the only user input will be a positive value in CM. The program has to check over where to move the line.

The shape will not be having only lines. It might also have splines.

No 2. Accepting a user input like a mouse click is Ok, since you said it will be difficult.

I have converted into RTF and posted again.
Attached Files
File Type: rtf Dear.rtf (47.2 KB, 5 views)
Reply With Quote
  #9  
Old 08-07-2008, 07:13 AM
mkaras's Avatar
mkaras mkaras is offline
Ultimate Contributor

Retired Leader
* Expert *
 
Join Date: Mar 2004
Location: Beaverton, OR
Posts: 1,874
Default

arunkish - I suspect that if you had made the drawing objects directly in your own code then the concept of adding the offset to the object would be very straightforward right in your code. In the case of the use of something like VECAD that manages a list of CAD drawing objects for you it will be quite a bit more difficult to directly manipulate and modify these managed objects directly in your code. This is why others have suggested the possibility of looking into the CAD drawing object control to see if it directly supports methods of modifying its objects.

Of course you can look carefully at each CAD drawing object type that you are able to create and make additional ones produce the outline effect that you desire. This would be straightforward for simple lines, circles and rectangles but for more complex types of objects it could be quite a challenge.
Reply With Quote
  #10  
Old 08-16-2008, 03:40 AM
arunkish arunkish is offline
Newcomer
 
Join Date: Aug 2008
Posts: 18
Default Outline for PolyGon

Hi,
I'm unable to figure out exactly how to add a border at the specified distance for a polygon that we create. I hope that anyone of you will be able to help me out with this. Please let me know some example code if you do have. Please take a look at the attachments for more info. Thanks for your time.

Please note that the attachment shown is only for an example. It does not have actual measurements.

Thanks and regards.
Attached Files
File Type: rtf Doc1.rtf (16.8 KB, 9 views)
Reply With Quote
  #11  
Old 08-16-2008, 05:58 AM
arunkish arunkish is offline
Newcomer
 
Join Date: Aug 2008
Posts: 18
Default

Please take a look at the attached image to give you a bit more idea on what I'm looking for....

Regards
Attached Images
File Type: jpg image.jpg (137.4 KB, 17 views)
Reply With Quote
  #12  
Old 08-17-2008, 06:39 PM
passel's Avatar
passel passel is offline
Sinecure Expert

Super Moderator
* Guru *
 
Join Date: Jun 2003
Location: Upstate New York, usa
Posts: 7,714
Default

What you say you're looking for in the second post doesn't match the document.
The document wants a parallel line, offset a fixed distance perpendicular to each original line.

Your drawing suggest doing a fixed distance horizontal or vertical (depending on the slope of the line) from the verticies of the lines. This will not give you the same shape as specified in the rtf document.

What is this for?
__________________
There Is An Island Of Opportunity In The Middle of Every Difficulty.
Miss That, Though, And You're Pretty Much Doomed.
Reply With Quote
  #13  
Old 08-17-2008, 08:21 PM
arunkish arunkish is offline
Newcomer
 
Join Date: Aug 2008
Posts: 18
Default

Passel,

The document was an example I created to indicate that the distance has to be the same for the outline, the original output may vary as u said. But the requirement is what I have mentioned in the document.

Regards
Reply With Quote
  #14  
Old 08-16-2008, 04:05 AM
arunkish arunkish is offline
Newcomer
 
Join Date: Aug 2008
Posts: 18
Default

Dear Gruff

Thank you very much. I will check it out and let you know about it.
Reply With Quote
  #15  
Old 08-18-2008, 03:15 AM
arunkish arunkish is offline
Newcomer
 
Join Date: Aug 2008
Posts: 18
Default Draw perpendicular line at 90 Degree

Hi all.

Looking for some help from you to draw a line perpendicular to the existing line at 90 degree.

(Line to be drawn)
|
|
|
|
-----------------------------( Given Line )

I hope that I can hear from you soon.
Reply With Quote
  #16  
Old 08-18-2008, 05:33 AM
m0skit0's Avatar
m0skit0 m0skit0 is offline
Centurion
 
Join Date: Jul 2008
Location: Madrid (Spain)
Posts: 151
Default

Knowing two points from the given line (X,Y) and (X',Y'), calculate a vector from it: <X-X',Y-Y'> = <W,Z>, this is the direction vector of your known line.

Then find a vector perpendicular to this one. This is done switching coordinates and changing the sign of one of them. For the given vector, these are the two perpendicular vectors: <-Z,W> and <Z,-W>.

Now it should be straightforward for you to construct the line; you got a point (X,Y) and a direction vector <-Z,W> or <Z,-W>.

Hope it is clear enough.
__________________
Use CODE wrappers and do not hurt my eyes!
Reply With Quote
  #17  
Old 08-18-2008, 10:46 AM
Gruff's Avatar
Gruff Gruff is offline
Bald Mountain Survivor

Super Moderator
* Expert *
 
Join Date: Aug 2003
Location: Oregon, USA
Posts: 5,879
Default

arunkish, In Your last thread Post #11

I Posted some code to find a line parallel at a distance from a given line.
If you think about it you need pretty much the same elements as you do to create a line perpendicular.
The 'Closest_Pt()' subroutine I posted is a line perpendicular engine.

This is a teaching forum. We do not normally hand out code on request.
As I said before you need to do some reading and/or take a class in geometry.

How do you expect to write code if you do not understand what the code is meant to manipulate?
__________________
Burn the land and boil the sea
You can't take the sky from me


~T

Last edited by Gruff; 08-18-2008 at 10:58 AM.
Reply With Quote
  #18  
Old 08-18-2008, 11:44 PM
arunkish arunkish is offline
Newcomer
 
Join Date: Aug 2008
Posts: 18
Default

Gruff,

I worked on to the code that you posted before, but that did not suite the with my application. Parallel lines did not work, as I said before creating an outline for a polygon ( concave / convex ) is my objective. Thank you for your advice to learn Geomentry. I'm not an expert in Math, I'm facting such difficulties since this is the first application I'm writing related to graphics ( lines , curves etc). Is there any ref for me so that I can learn certain things as u said. Thanks in advance.
Reply With Quote
  #19  
Old 08-18-2008, 11:45 PM
arunkish arunkish is offline
Newcomer
 
Join Date: Aug 2008
Posts: 18
Default

Gruff,

I figured out to do it. Thanks everyone for your help.
Reply With Quote
  #20  
Old 08-19-2008, 12:05 AM
arunkish arunkish is offline
Newcomer
 
Join Date: Aug 2008
Posts: 18
Default

Please take a look at the attachment. This was the output when drawing parallel lines. But the the output did not match the original shape. Anyhow I'm using the IsEqual Functions and certain other things that was very useful for me.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->