473,506 Members | 16,970 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

[Maths] Drawing lines to shapes

28 New Member
Hi,

I'm making a brainstorming program in VB.net and am struggling with drawing arrow lines. Currently I have lines that go all the way to the centre of a 'bubble' on the screen. This works very well but I want to implement lines with arrows to show flow.

I need the lines to stop just before it gets to the bounds of the bubble otherwise the arrow head will be drawn under the shape.

I've been trying for hours to get this to work. I've tried Pythagoras and sin cos tan but nothing seems to work well.

The current code I have isn't working:
Expand|Select|Wrap|Line Numbers
  1.    If (lastPoint.X < firstPoint.X) Then
  2.                     If (lastPoint.Y < firstPoint.Y) Then
  3.                         '' bottom left
  4.                         Dim x As Double = Math.Atan((firstPoint.X - lastPoint.X) / (firstPoint.Y - lastPoint.Y))
  5.                         Dim s2 As Double = Math.Tan(x) * (endSize.Height / 2)
  6.  
  7.                         Dim newX As Double = lastPoint.X + s2
  8.                         Dim newY As Double = lastPoint.Y
  9.                         alteredLastPoint = New Point(newX, newY)
  10.                     Else
  11.                         '' top left
  12.                         Dim x As Double = Math.Atan((firstPoint.X - lastPoint.X) / (firstPoint.Y - lastPoint.Y))
  13.                         Dim s2 As Double = Math.Tan(x) * (endSize.Height / 2)
  14.  
  15.                         Dim newX As Double = lastPoint.X + s2
  16.                         Dim newY As Double = lastPoint.Y + endSize.Height
  17.                         alteredLastPoint = New Point(newX, newY)
  18.                     End If
  19.                 Else
  20.                     If (lastPoint.Y < firstPoint.Y) Then
  21.                         '' bottom right
  22.                         Dim x As Double = Math.Atan((firstPoint.X - lastPoint.X) / (firstPoint.Y - lastPoint.Y))
  23.                         Dim s2 As Double = Math.Tan(x) * (endSize.Height / 2)
  24.  
  25.                         Dim newX As Double = lastPoint.X + s2
  26.                         Dim newY As Double = lastPoint.Y
  27.                         alteredLastPoint = New Point(newX, newY)
  28.                     Else
  29.                         '' top right
  30.                         Dim x As Double = Math.Atan((firstPoint.X - lastPoint.X) / (firstPoint.Y - lastPoint.Y))
  31.                         Dim s2 As Double = Math.Tan(x) * (endSize.Height / 2)
  32.  
  33.                         Dim newX As Double = lastPoint.X + s2
  34.                         Dim newY As Double = lastPoint.Y + endSize.Height
  35.                         alteredLastPoint = New Point(newX, newY)
  36.                     End If
  37.                 End If
It vaguely works but is by far not perfect. I am quite new to this kind of maths so it's probably just something simple that I'm forgetting.

alteredLastPoint is the point for the where the arrow head will be drawn.
lastPoint is the centre point of the bubble where the arrow head is meant to point to
firstPoint is the centre point of the bubble where the arrow will come from
endSize is the size of the bubble where the arrow points to.

Thanks in advance,
Josh.
Feb 2 '13 #1
0 1137

Sign in to post your reply or Sign up for a free account.

Similar topics

0
1597
by: Michael Kalina | last post by:
Hi! I have a problem with my CSS and Mozilla Firefox as well as Opera 7.xx: On my homepage http://michaelsremarks.com, I use a BlogRoll. When the page loads, there is a break of all the lines in...
8
22378
by: john | last post by:
Hi I am a C++ newbie, I am looking to draw single lines and simple boxes in a C++ console window. Is there a draw command with x and y coordinates that can be used with my Dev C++ compiler. For...
10
2307
by: Zach | last post by:
In an invoicing program I draw lines in a text file using: new string ("-",73) new string ("=",73) These lines look awful. Is there a better way? Much obliged.
5
2361
by: Manuel Daponte | last post by:
I found this code in this newsgroup and used it, but the lines drawn are composed of point too separated when the mouse moves at medium or fast speed. How can I fix it? Thanks in advance !!! ...
9
3160
by: davetelling | last post by:
I am not a programmer, I'm an engineer trying to make an interface to a product I'm designing. I have used C# to make a form that interrogates the unit via the serial port and receives the data. I...
3
2876
by: Christie | last post by:
I am writing my app using Visual Studio 2005 (VB.NET). I want to draw images (nothing complex, just lines and shapes) using a mouse. How do one go about achieving this with VB.NET?? If someone...
0
1187
by: =?Utf-8?B?UmF5IE1pdGNoZWxs?= | last post by:
I have a form that I'm drawing some lines on using the DrawLines method. It all works fine as long as I don't try to draw these lines inside a group box. When I do, however, the lines don't show. ...
4
3767
by: =?Utf-8?B?R2lkaQ==?= | last post by:
Hi, I've windows form, in this form i've a panel. I want to draw lines inside the panel using the panel coordinates( meaing that the left upper corner of the panel is 0,0), how can i do it? ...
0
1104
by: BarryM | last post by:
Iv got a panel on the main form which is set to auto scroll. In the panel there is a picture box that i draw lines in. the lines work perfectly fine until the scroll bar comes up. The picture box...
0
7307
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7370
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7021
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7478
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5035
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3188
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1532
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
755
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
409
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.