473,732 Members | 2,201 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Moving pivot locations using Trigonometry

Hi

I have a math kinda problem where I'm trying to split some lines when two or
more lines connect two shapes. The reason I am doing this is to make it
clear that there are multiple lines connecting the two shapes.

http://www.blackwaterbadgers.co.uk/image1.bmp

Image 1 shows how if you have a line between two shapes, the line is
straight. if you have more than one line, the lines will start overlapping
each other and essentially look like just the one line. What I have done is
to add a pivot to the centre of the line so the lines can be given a curve
as shown in Image 1.

The middle pivot is created when the line is straight so I know its
location. I also know the locations of either end of the line so from this
I can get the angle of the line. I also know the distance by which I want
to offset the middle pivot.

My plan is to run some code (most of this I have written) that looks to see
how many lines are going between the two shapes. If it is one line then I
will leave it alone. If it is more than one line, I want to separate out
the lines.

http://www.blackwaterbadgers.co.uk/image2.bmp

Based on Image 2
I know the location of the two red dots which give me oppA and adjA, from
this I can get the angle x. As I want the middle pivot to move at a right
angle to its origin, I know the angle of y.
hypB is the distance I want to move the pivot from its origin so from this I
can get oppB and adjB.

Based on the middle pivot, I can now use these measurements to offset the
middle pivot.

The only problem is, because I have used Math.Abs to ensure that I now
working with negative numbers, I now need to establish the direction in
which I want to offset the pivot. This isn't too much of a problem but I am
having trouble working out the distance by which to offset the pivot based
on the number of lines.

So my question is, how can I determine the offset direct and length based on
the number of lines?

Ideally, I would like to split the lines evenly so that if I had an odd
number of lines then the middle line would stay straight with the remaining
lines either side. If I have an even number of lines then the lines would
be split evenly.

A colleague suggested going through each line and offsetting each pivot in
the same direction and then moving all the pivots back to a more central
position but I'm sure it would be better to just work out the direction to
move each pivot and by how much.

Does anyone have any idea on how I could achieve this?

Regards, Carl Gilbert
Nov 21 '05 #1
2 3111
Sounds to me like a job for beziers...

You'll find a little VB application after my signature.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.
Imports System.Drawing. Drawing2D

Public Class Form1

Inherits System.Windows. Forms.Form

#Region " Windows Form Designer generated code "

Public Sub New()

MyBase.New()

'This call is required by the Windows Form Designer.

InitializeCompo nent()

'Add any initialization after the InitializeCompo nent() call

End Sub

'Form overrides dispose to clean up the component list.

Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)

If disposing Then

If Not (components Is Nothing) Then

components.Disp ose()

End If

End If

MyBase.Dispose( disposing)

End Sub

'Required by the Windows Form Designer

Private components As System.Componen tModel.IContain er

'NOTE: The following procedure is required by the Windows Form Designer

'It can be modified using the Windows Form Designer.

'Do not modify it using the code editor.

Friend WithEvents NumericUpDown1 As System.Windows. Forms.NumericUp Down

Friend WithEvents Label1 As System.Windows. Forms.Label

Friend WithEvents Label2 As System.Windows. Forms.Label

Friend WithEvents NumericUpDown2 As System.Windows. Forms.NumericUp Down

<System.Diagnos tics.DebuggerSt epThrough()> Private Sub InitializeCompo nent()

Me.NumericUpDow n1 = New System.Windows. Forms.NumericUp Down

Me.Label1 = New System.Windows. Forms.Label

Me.Label2 = New System.Windows. Forms.Label

Me.NumericUpDow n2 = New System.Windows. Forms.NumericUp Down

CType(Me.Numeri cUpDown1,
System.Componen tModel.ISupport Initialize).Beg inInit()

CType(Me.Numeri cUpDown2,
System.Componen tModel.ISupport Initialize).Beg inInit()

Me.SuspendLayou t()

'

'NumericUpDown1

'

Me.NumericUpDow n1.Location = New System.Drawing. Point(72, 16)

Me.NumericUpDow n1.Maximum = New Decimal(New Integer() {10, 0, 0, 0})

Me.NumericUpDow n1.Minimum = New Decimal(New Integer() {1, 0, 0, 0})

Me.NumericUpDow n1.Name = "NumericUpDown1 "

Me.NumericUpDow n1.Size = New System.Drawing. Size(72, 20)

Me.NumericUpDow n1.TabIndex = 0

Me.NumericUpDow n1.Value = New Decimal(New Integer() {3, 0, 0, 0})

'

'Label1

'

Me.Label1.Locat ion = New System.Drawing. Point(8, 16)

Me.Label1.Name = "Label1"

Me.Label1.Size = New System.Drawing. Size(40, 23)

Me.Label1.TabIn dex = 1

Me.Label1.Text = "Lines"

'

'Label2

'

Me.Label2.Locat ion = New System.Drawing. Point(8, 48)

Me.Label2.Name = "Label2"

Me.Label2.Size = New System.Drawing. Size(56, 23)

Me.Label2.TabIn dex = 2

Me.Label2.Text = "Degrees"

'

'NumericUpDown2

'

Me.NumericUpDow n2.Location = New System.Drawing. Point(72, 48)

Me.NumericUpDow n2.Maximum = New Decimal(New Integer() {90, 0, 0, 0})

Me.NumericUpDow n2.Minimum = New Decimal(New Integer() {1, 0, 0, 0})

Me.NumericUpDow n2.Name = "NumericUpDown2 "

Me.NumericUpDow n2.Size = New System.Drawing. Size(72, 20)

Me.NumericUpDow n2.TabIndex = 0

Me.NumericUpDow n2.Value = New Decimal(New Integer() {1, 0, 0, 0})

'

'Form1

'

Me.AutoScaleBas eSize = New System.Drawing. Size(5, 13)

Me.ClientSize = New System.Drawing. Size(448, 382)

Me.Controls.Add (Me.Label2)

Me.Controls.Add (Me.Label1)

Me.Controls.Add (Me.NumericUpDo wn1)

Me.Controls.Add (Me.NumericUpDo wn2)

Me.Name = "Form1"

Me.Text = "Form1"

CType(Me.Numeri cUpDown1, System.Componen tModel.ISupport Initialize).End Init()

CType(Me.Numeri cUpDown2, System.Componen tModel.ISupport Initialize).End Init()

Me.ResumeLayout (False)

End Sub

#End Region

Protected Overrides Sub OnMouseMove(ByV al e As
System.Windows. Forms.MouseEven tArgs)

mouse = New Point(e.X, e.Y)

Invalidate()

End Sub

Dim mouse As Point

Protected Overrides Sub OnPaint(ByVal e As
System.Windows. Forms.PaintEven tArgs)

Dim n As Integer

Dim absoluteangle As Single = 0

For n = 0 To Me.NumericUpDow n1.Value - 1

Dim rotationangle As Single

If (n Mod 2 = 0) Then

rotationangle = absoluteangle

Else

rotationangle = -absoluteangle

End If

Dim firstPoint As PointF = New PointF(Me.Clien tRectangle.Widt h / 2, 20)

Dim lastpoint As PointF = New PointF(mouse.X, mouse.Y)

Dim vector As PointF = New PointF(lastpoin t.X - firstPoint.X, lastpoint.Y -
firstPoint.Y)

'get the hypotenuse...

Dim hypot As Single = CSng(Math.Sqrt( (vector.X * vector.X) + (vector.Y *
vector.Y)))

'create a point at the center of the hypotenuse...

Dim center As New PointF(firstPoi nt.X + (vector.X / 2), firstPoint.Y +
(vector.Y / 2))

'Create bezier control points

Dim cp1 As PointF() = New PointF() {center}

Dim cp2 As PointF() = New PointF() {center}

'rotate one point around the first position...

Dim mx As New Matrix

mx.RotateAt(rot ationangle, firstPoint)

mx.TransformPoi nts(cp1)

'rotate the other point around the last position...

mx = New Matrix

mx.RotateAt(-rotationangle, lastpoint)

mx.TransformPoi nts(cp2)

'draw a bezier

e.Graphics.Draw Bezier(Pens.Bla ck, firstPoint, cp1(0), cp2(0), lastpoint)

absoluteangle += Me.NumericUpDow n2.Value

Next

End Sub

End Class

"Carl Gilbert" <cn*@newsgroup. nospam> wrote in message
news:uz******** *****@TK2MSFTNG P10.phx.gbl...
Hi

I have a math kinda problem where I'm trying to split some lines when two
or more lines connect two shapes. The reason I am doing this is to make
it clear that there are multiple lines connecting the two shapes.

http://www.blackwaterbadgers.co.uk/image1.bmp

Image 1 shows how if you have a line between two shapes, the line is
straight. if you have more than one line, the lines will start
overlapping each other and essentially look like just the one line. What
I have done is to add a pivot to the centre of the line so the lines can
be given a curve as shown in Image 1.

The middle pivot is created when the line is straight so I know its
location. I also know the locations of either end of the line so from
this I can get the angle of the line. I also know the distance by which I
want to offset the middle pivot.

My plan is to run some code (most of this I have written) that looks to
see how many lines are going between the two shapes. If it is one line
then I will leave it alone. If it is more than one line, I want to
separate out the lines.

http://www.blackwaterbadgers.co.uk/image2.bmp

Based on Image 2
I know the location of the two red dots which give me oppA and adjA, from
this I can get the angle x. As I want the middle pivot to move at a right
angle to its origin, I know the angle of y.
hypB is the distance I want to move the pivot from its origin so from this
I can get oppB and adjB.

Based on the middle pivot, I can now use these measurements to offset the
middle pivot.

The only problem is, because I have used Math.Abs to ensure that I now
working with negative numbers, I now need to establish the direction in
which I want to offset the pivot. This isn't too much of a problem but I
am having trouble working out the distance by which to offset the pivot
based on the number of lines.

So my question is, how can I determine the offset direct and length based
on the number of lines?

Ideally, I would like to split the lines evenly so that if I had an odd
number of lines then the middle line would stay straight with the
remaining lines either side. If I have an even number of lines then the
lines would be split evenly.

A colleague suggested going through each line and offsetting each pivot in
the same direction and then moving all the pivots back to a more central
position but I'm sure it would be better to just work out the direction to
move each pivot and by how much.

Does anyone have any idea on how I could achieve this?

Regards, Carl Gilbert

Nov 21 '05 #2
Thanks Bob

Your code worked just fine with a bit of tweaking.

Regards, Carl

Nov 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
2106
by: Prasad Patil | last post by:
Hi, I have created a report in excel, it uses Pivot tables. The excel has two sheets 1: Pivot ( Contains the Pivot Table) 2: Data (Data Requred to populate the pivot table I create an instance of Excel populate the data sheet and load excel in the browser.
2
5843
by: Rob | last post by:
I'm just getting around to using pivot tables and charts. I find the Pivot table interface to be INCREDIBLY frustrating. When I view a table in Design view, then choose Pivot table view, I get the PivotTable Field list, from which I can choose to add fields to the view. 1. How do you get RID of a field once you put it in? I can not right click on anywhere in the view and have ANY of the submenu options be availble. From the PivotTable...
1
3145
by: Grey | last post by:
I have created a asp.net form for user to input data. After input the data, user need to click a button to export the input data to excel for data analysis with excel pivot table function. is it possible to do that?? if so, any sample for me as i am a new in designing pivot table with asp.net million thanks
3
10265
by: Jerry K via DotNetMonster.com | last post by:
I'm creating a pivot table using vb.net and the data is from sqlserver (desktop). I have been successful at creating the pivot table, which includes a 'date' column field. I'd like to group the date column field by months and quarters, but can't come up with the correct code. Here is the code I've written to create the pivot table. Any help to code grouping the date column field would be appreciated. Thanks, Jerry
1
7353
by: kingster | last post by:
Hi, I have a regular dataset and all i want to do is make a pivot table display in a browser with the datasource of the pivot table to be this dataset and then the end-user will be able to do whatever they want ... i dont need to do any special formatting just a straigh ot pivot tables usign sql server, asp.net, vb.net, OWC 10
3
8489
by: nikila | last post by:
Hi, I have to create excel pivot tables from vb.net. Already I am creating excel file using oledb connection. I want to use the same to create the excel pivot tables. Can anyone please help me on this. It is very urgent. Please reply immediately Thanks for the help!!!! nikila
9
6796
by: PeteCresswell | last post by:
I've got something called "Reference Rates". The idea is that on a given day, we have various rates of return for various entities. e.g. Libor 3-month return, Libor 6-month return, US Treasury Bonds, the Prime rate, and so-forth. We associate a security with one of those rates. There are a set of rates for each calendar day, and the rates for that
0
1455
by: linkswanted | last post by:
World Moving & Storage Moving Companies and Movers We would like to take this opportunity to introduce "World Moving & Storage" to You. "World Moving & Storage" is well established, Fully Licensed, Insured and Bonded. A Moving & Storage Company based in North Hollywood and San Francisco, California. Our services range from local to long distance and International moves throughout the United States. We offer Express Moves To All Major...
1
1925
by: STUFIX | last post by:
Hi all, I created a pivot table that allowed users to select certain customers from a drop down list and display the relevant data - it worked fine but has now stopped allowing them to do that. At the same time, I can no longer create a Pivot Table with page, row or column fileds. All of the Pivot Table menu items except Refresh Data have greyed out. I've tried creating a new db with a simple table and pivot and it is the same issue, so...
0
8946
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8774
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
9235
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9181
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8186
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6031
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4809
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2721
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2180
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.