├── .gitattributes
├── .gitignore
├── GeometRi.Tests
├── GeometRi.Tests.vbproj
├── GeometRiTest.vb
└── My Project
│ ├── Application.Designer.vb
│ ├── Application.myapp
│ ├── AssemblyInfo.vb
│ ├── Resources.Designer.vb
│ ├── Resources.resx
│ ├── Settings.Designer.vb
│ └── Settings.settings
├── GeometRi.sln
├── GeometRi
├── GeometRi.vbproj
├── GeometRi
│ ├── Circle3D.vb
│ ├── Coord3D.vb
│ ├── Ellipse.vb
│ ├── GeometRi3D.vb
│ ├── Line3D.vb
│ ├── Matrix3D.vb
│ ├── Plane3D.vb
│ ├── Point3D.vb
│ ├── Ray3D.vb
│ ├── Segment3D.vb
│ ├── Sphere.vb
│ ├── Triangle.vb
│ └── Vector3D.vb
└── My Project
│ ├── Application.Designer.vb
│ ├── Application.myapp
│ ├── AssemblyInfo.vb
│ ├── Resources.Designer.vb
│ ├── Resources.resx
│ ├── Settings.Designer.vb
│ └── Settings.settings
├── GeometRiExample.CSharp
├── GeometRiExample.CSharp.csproj
├── Program.cs
├── Properties
│ └── AssemblyInfo.cs
└── app.config
├── GeometRiExample
├── GeometRiExample.vbproj
├── Module1.vb
├── My Project
│ ├── Application.Designer.vb
│ ├── Application.myapp
│ ├── AssemblyInfo.vb
│ ├── Resources.Designer.vb
│ ├── Resources.resx
│ ├── Settings.Designer.vb
│ └── Settings.settings
└── app.config
├── LICENSE.txt
└── README.md
/.gitattributes:
--------------------------------------------------------------------------------
1 | ###############################################################################
2 | # Set default behavior to automatically normalize line endings.
3 | ###############################################################################
4 | * text=auto
5 |
6 | ###############################################################################
7 | # Set default behavior for command prompt diff.
8 | #
9 | # This is need for earlier builds of msysgit that does not have it on by
10 | # default for csharp files.
11 | # Note: This is only used by command line
12 | ###############################################################################
13 | #*.cs diff=csharp
14 |
15 | ###############################################################################
16 | # Set the merge driver for project and solution files
17 | #
18 | # Merging from the command prompt will add diff markers to the files if there
19 | # are conflicts (Merging from VS is not affected by the settings below, in VS
20 | # the diff markers are never inserted). Diff markers may cause the following
21 | # file extensions to fail to load in VS. An alternative would be to treat
22 | # these files as binary and thus will always conflict and require user
23 | # intervention with every merge. To do so, just uncomment the entries below
24 | ###############################################################################
25 | #*.sln merge=binary
26 | #*.csproj merge=binary
27 | #*.vbproj merge=binary
28 | #*.vcxproj merge=binary
29 | #*.vcproj merge=binary
30 | #*.dbproj merge=binary
31 | #*.fsproj merge=binary
32 | #*.lsproj merge=binary
33 | #*.wixproj merge=binary
34 | #*.modelproj merge=binary
35 | #*.sqlproj merge=binary
36 | #*.wwaproj merge=binary
37 |
38 | ###############################################################################
39 | # behavior for image files
40 | #
41 | # image files are treated as binary by default.
42 | ###############################################################################
43 | #*.jpg binary
44 | #*.png binary
45 | #*.gif binary
46 |
47 | ###############################################################################
48 | # diff behavior for common document formats
49 | #
50 | # Convert binary document formats to text before diffing them. This feature
51 | # is only available from the command line. Turn it on by uncommenting the
52 | # entries below.
53 | ###############################################################################
54 | #*.doc diff=astextplain
55 | #*.DOC diff=astextplain
56 | #*.docx diff=astextplain
57 | #*.DOCX diff=astextplain
58 | #*.dot diff=astextplain
59 | #*.DOT diff=astextplain
60 | #*.pdf diff=astextplain
61 | #*.PDF diff=astextplain
62 | #*.rtf diff=astextplain
63 | #*.RTF diff=astextplain
64 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | ## Ignore Visual Studio temporary files, build results, and
2 | ## files generated by popular Visual Studio add-ons.
3 |
4 | # User-specific files
5 | *.suo
6 | *.user
7 | *.userosscache
8 | *.sln.docstates
9 |
10 | # User-specific files (MonoDevelop/Xamarin Studio)
11 | *.userprefs
12 |
13 | # Build results
14 | [Dd]ebug/
15 | [Dd]ebugPublic/
16 | [Rr]elease/
17 | [Rr]eleases/
18 | [Xx]64/
19 | [Xx]86/
20 | [Bb]uild/
21 | bld/
22 | [Bb]in/
23 | [Oo]bj/
24 |
25 | # Visual Studio 2015 cache/options directory
26 | .vs/
27 | # Uncomment if you have tasks that create the project's static files in wwwroot
28 | #wwwroot/
29 |
30 | # MSTest test Results
31 | [Tt]est[Rr]esult*/
32 | [Bb]uild[Ll]og.*
33 |
34 | # NUNIT
35 | *.VisualState.xml
36 | TestResult.xml
37 |
38 | # Build Results of an ATL Project
39 | [Dd]ebugPS/
40 | [Rr]eleasePS/
41 | dlldata.c
42 |
43 | # DNX
44 | project.lock.json
45 | artifacts/
46 |
47 | *_i.c
48 | *_p.c
49 | *_i.h
50 | *.ilk
51 | *.meta
52 | *.obj
53 | *.pch
54 | *.pdb
55 | *.pgc
56 | *.pgd
57 | *.rsp
58 | *.sbr
59 | *.tlb
60 | *.tli
61 | *.tlh
62 | *.tmp
63 | *.tmp_proj
64 | *.log
65 | *.vspscc
66 | *.vssscc
67 | .builds
68 | *.pidb
69 | *.svclog
70 | *.scc
71 |
72 | # Chutzpah Test files
73 | _Chutzpah*
74 |
75 | # Visual C++ cache files
76 | ipch/
77 | *.aps
78 | *.ncb
79 | *.opendb
80 | *.opensdf
81 | *.sdf
82 | *.cachefile
83 | *.VC.db
84 |
85 | # Visual Studio profiler
86 | *.psess
87 | *.vsp
88 | *.vspx
89 | *.sap
90 |
91 | # TFS 2012 Local Workspace
92 | $tf/
93 |
94 | # Guidance Automation Toolkit
95 | *.gpState
96 |
97 | # ReSharper is a .NET coding add-in
98 | _ReSharper*/
99 | *.[Rr]e[Ss]harper
100 | *.DotSettings.user
101 |
102 | # JustCode is a .NET coding add-in
103 | .JustCode
104 |
105 | # TeamCity is a build add-in
106 | _TeamCity*
107 |
108 | # DotCover is a Code Coverage Tool
109 | *.dotCover
110 |
111 | # NCrunch
112 | _NCrunch_*
113 | .*crunch*.local.xml
114 | nCrunchTemp_*
115 |
116 | # MightyMoose
117 | *.mm.*
118 | AutoTest.Net/
119 |
120 | # Web workbench (sass)
121 | .sass-cache/
122 |
123 | # Installshield output folder
124 | [Ee]xpress/
125 |
126 | # DocProject is a documentation generator add-in
127 | DocProject/buildhelp/
128 | DocProject/Help/*.HxT
129 | DocProject/Help/*.HxC
130 | DocProject/Help/*.hhc
131 | DocProject/Help/*.hhk
132 | DocProject/Help/*.hhp
133 | DocProject/Help/Html2
134 | DocProject/Help/html
135 |
136 | # Click-Once directory
137 | publish/
138 |
139 | # Publish Web Output
140 | *.[Pp]ublish.xml
141 | *.azurePubxml
142 |
143 | # TODO: Un-comment the next line if you do not want to checkin
144 | # your web deploy settings because they may include unencrypted
145 | # passwords
146 | #*.pubxml
147 | *.publishproj
148 |
149 | # NuGet Packages
150 | *.nupkg
151 | # The packages folder can be ignored because of Package Restore
152 | **/packages/*
153 | # except build/, which is used as an MSBuild target.
154 | !**/packages/build/
155 | # Uncomment if necessary however generally it will be regenerated when needed
156 | #!**/packages/repositories.config
157 | # NuGet v3's project.json files produces more ignoreable files
158 | *.nuget.props
159 | *.nuget.targets
160 |
161 | # Microsoft Azure Build Output
162 | csx/
163 | *.build.csdef
164 |
165 | # Microsoft Azure Emulator
166 | ecf/
167 | rcf/
168 |
169 | # Windows Store app package directory
170 | AppPackages/
171 | BundleArtifacts/
172 |
173 | # Visual Studio cache files
174 | # files ending in .cache can be ignored
175 | *.[Cc]ache
176 | # but keep track of directories ending in .cache
177 | !*.[Cc]ache/
178 |
179 | # Others
180 | ClientBin/
181 | [Ss]tyle[Cc]op.*
182 | ~$*
183 | *~
184 | *.dbmdl
185 | *.dbproj.schemaview
186 | *.pfx
187 | *.publishsettings
188 | node_modules/
189 | orleans.codegen.cs
190 |
191 | # RIA/Silverlight projects
192 | Generated_Code/
193 |
194 | # Backup & report files from converting an old project file
195 | # to a newer Visual Studio version. Backup files are not needed,
196 | # because we have git ;-)
197 | _UpgradeReport_Files/
198 | Backup*/
199 | UpgradeLog*.XML
200 | UpgradeLog*.htm
201 |
202 | # SQL Server files
203 | *.mdf
204 | *.ldf
205 |
206 | # Business Intelligence projects
207 | *.rdl.data
208 | *.bim.layout
209 | *.bim_*.settings
210 |
211 | # Microsoft Fakes
212 | FakesAssemblies/
213 |
214 | # GhostDoc plugin setting file
215 | *.GhostDoc.xml
216 |
217 | # Node.js Tools for Visual Studio
218 | .ntvs_analysis.dat
219 |
220 | # Visual Studio 6 build log
221 | *.plg
222 |
223 | # Visual Studio 6 workspace options file
224 | *.opt
225 |
226 | # Visual Studio LightSwitch build output
227 | **/*.HTMLClient/GeneratedArtifacts
228 | **/*.DesktopClient/GeneratedArtifacts
229 | **/*.DesktopClient/ModelManifest.xml
230 | **/*.Server/GeneratedArtifacts
231 | **/*.Server/ModelManifest.xml
232 | _Pvt_Extensions
233 |
234 | # LightSwitch generated files
235 | GeneratedArtifacts/
236 | ModelManifest.xml
237 |
238 | # Paket dependency manager
239 | .paket/paket.exe
240 |
241 | # FAKE - F# Make
242 | .fake/
243 |
--------------------------------------------------------------------------------
/GeometRi.Tests/GeometRi.Tests.vbproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Debug
5 | AnyCPU
6 | {6A3E686B-4E54-45CC-9CE0-57FD8304DFCA}
7 | Library
8 | GeometRi.Tests
9 | GeometRi.Tests
10 | 512
11 | Windows
12 | v4.0
13 | {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{F184B08F-C81C-45F6-A57F-5ABD9991F28F}
14 | 10.0
15 | $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)
16 | $(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages
17 | False
18 | UnitTest
19 |
20 |
21 |
22 | true
23 | full
24 | true
25 | true
26 | bin\Debug\
27 | GeometRi.Tests.xml
28 | 42016,41999,42017,42018,42019,42032,42036,42020,42021,42022
29 |
30 |
31 | pdbonly
32 | false
33 | true
34 | true
35 | bin\Release\
36 | GeometRi.Tests.xml
37 | 42016,41999,42017,42018,42019,42032,42036,42020,42021,42022
38 |
39 |
40 | On
41 |
42 |
43 | Binary
44 |
45 |
46 | Off
47 |
48 |
49 | On
50 |
51 |
52 |
53 | False
54 | ..\GeometRi\bin\Debug\GeometRi.dll
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 | True
91 | Application.myapp
92 |
93 |
94 | True
95 | True
96 | Resources.resx
97 |
98 |
99 | True
100 | Settings.settings
101 | True
102 |
103 |
104 |
105 |
106 | VbMyResourcesResXFileCodeGenerator
107 | Resources.Designer.vb
108 | My.Resources
109 | Designer
110 |
111 |
112 |
113 |
114 | MyApplicationCodeGenerator
115 | Application.Designer.vb
116 |
117 |
118 | SettingsSingleFileGenerator
119 | My
120 | Settings.Designer.vb
121 |
122 |
123 |
124 |
125 |
126 |
127 | False
128 |
129 |
130 | False
131 |
132 |
133 | False
134 |
135 |
136 | False
137 |
138 |
139 |
140 |
141 |
142 |
143 |
150 |
--------------------------------------------------------------------------------
/GeometRi.Tests/My Project/Application.Designer.vb:
--------------------------------------------------------------------------------
1 | '------------------------------------------------------------------------------
2 | '
3 | ' This code was generated by a tool.
4 | ' Runtime Version:4.0.30319.42000
5 | '
6 | ' Changes to this file may cause incorrect behavior and will be lost if
7 | ' the code is regenerated.
8 | '
9 | '------------------------------------------------------------------------------
10 |
11 | Option Strict On
12 | Option Explicit On
13 |
14 |
--------------------------------------------------------------------------------
/GeometRi.Tests/My Project/Application.myapp:
--------------------------------------------------------------------------------
1 |
2 |
3 | false
4 | false
5 | 0
6 | true
7 | 0
8 | 1
9 | true
10 |
11 |
--------------------------------------------------------------------------------
/GeometRi.Tests/My Project/AssemblyInfo.vb:
--------------------------------------------------------------------------------
1 | Imports System
2 | Imports System.Reflection
3 | Imports System.Runtime.InteropServices
4 |
5 | ' General Information about an assembly is controlled through the following
6 | ' set of attributes. Change these attribute values to modify the information
7 | ' associated with an assembly.
8 |
9 | ' Review the values of the assembly attributes
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 | 'The following GUID is for the ID of the typelib if this project is exposed to COM
21 |
22 |
23 | ' Version information for an assembly consists of the following four values:
24 | '
25 | ' Major Version
26 | ' Minor Version
27 | ' Build Number
28 | ' Revision
29 | '
30 | ' You can specify all the values or you can default the Build and Revision Numbers
31 | ' by using the '*' as shown below:
32 | '
33 |
34 |
35 |
36 |
--------------------------------------------------------------------------------
/GeometRi.Tests/My Project/Resources.Designer.vb:
--------------------------------------------------------------------------------
1 | '------------------------------------------------------------------------------
2 | '
3 | ' This code was generated by a tool.
4 | ' Runtime Version:4.0.30319.42000
5 | '
6 | ' Changes to this file may cause incorrect behavior and will be lost if
7 | ' the code is regenerated.
8 | '
9 | '------------------------------------------------------------------------------
10 |
11 | Option Strict On
12 | Option Explicit On
13 |
14 | Imports System
15 |
16 | Namespace My.Resources
17 |
18 | 'This class was auto-generated by the StronglyTypedResourceBuilder
19 | 'class via a tool like ResGen or Visual Studio.
20 | 'To add or remove a member, edit your .ResX file then rerun ResGen
21 | 'with the /str option, or rebuild your VS project.
22 | '''
23 | ''' A strongly-typed resource class, for looking up localized strings, etc.
24 | '''
25 | _
29 | Friend Module Resources
30 |
31 | Private resourceMan As Global.System.Resources.ResourceManager
32 |
33 | Private resourceCulture As Global.System.Globalization.CultureInfo
34 |
35 | '''
36 | ''' Returns the cached ResourceManager instance used by this class.
37 | '''
38 | _
39 | Friend ReadOnly Property ResourceManager() As Global.System.Resources.ResourceManager
40 | Get
41 | If Object.ReferenceEquals(resourceMan, Nothing) Then
42 | Dim temp As Global.System.Resources.ResourceManager = New Global.System.Resources.ResourceManager("GeometRi.Tests.Resources", GetType(Resources).Assembly)
43 | resourceMan = temp
44 | End If
45 | Return resourceMan
46 | End Get
47 | End Property
48 |
49 | '''
50 | ''' Overrides the current thread's CurrentUICulture property for all
51 | ''' resource lookups using this strongly typed resource class.
52 | '''
53 | _
54 | Friend Property Culture() As Global.System.Globalization.CultureInfo
55 | Get
56 | Return resourceCulture
57 | End Get
58 | Set
59 | resourceCulture = value
60 | End Set
61 | End Property
62 | End Module
63 | End Namespace
64 |
--------------------------------------------------------------------------------
/GeometRi.Tests/My Project/Resources.resx:
--------------------------------------------------------------------------------
1 |
2 |
3 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 | text/microsoft-resx
107 |
108 |
109 | 2.0
110 |
111 |
112 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
113 |
114 |
115 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
116 |
117 |
--------------------------------------------------------------------------------
/GeometRi.Tests/My Project/Settings.Designer.vb:
--------------------------------------------------------------------------------
1 | '------------------------------------------------------------------------------
2 | '
3 | ' This code was generated by a tool.
4 | ' Runtime Version:4.0.30319.42000
5 | '
6 | ' Changes to this file may cause incorrect behavior and will be lost if
7 | ' the code is regenerated.
8 | '
9 | '------------------------------------------------------------------------------
10 |
11 | Option Strict On
12 | Option Explicit On
13 |
14 |
15 | Namespace My
16 |
17 | _
20 | Partial Friend NotInheritable Class MySettings
21 | Inherits Global.System.Configuration.ApplicationSettingsBase
22 |
23 | Private Shared defaultInstance As MySettings = CType(Global.System.Configuration.ApplicationSettingsBase.Synchronized(New MySettings()),MySettings)
24 |
25 | #Region "My.Settings Auto-Save Functionality"
26 | #If _MyType = "WindowsForms" Then
27 | Private Shared addedHandler As Boolean
28 |
29 | Private Shared addedHandlerLockObject As New Object
30 |
31 | _
32 | Private Shared Sub AutoSaveSettings(ByVal sender As Global.System.Object, ByVal e As Global.System.EventArgs)
33 | If My.Application.SaveMySettingsOnExit Then
34 | My.Settings.Save()
35 | End If
36 | End Sub
37 | #End If
38 | #End Region
39 |
40 | Public Shared ReadOnly Property [Default]() As MySettings
41 | Get
42 |
43 | #If _MyType = "WindowsForms" Then
44 | If Not addedHandler Then
45 | SyncLock addedHandlerLockObject
46 | If Not addedHandler Then
47 | AddHandler My.Application.Shutdown, AddressOf AutoSaveSettings
48 | addedHandler = True
49 | End If
50 | End SyncLock
51 | End If
52 | #End If
53 | Return defaultInstance
54 | End Get
55 | End Property
56 | End Class
57 | End Namespace
58 |
59 | Namespace My
60 |
61 | _
64 | Friend Module MySettingsProperty
65 |
66 | _
67 | Friend ReadOnly Property Settings() As Global.GeometRi.Tests.My.MySettings
68 | Get
69 | Return Global.GeometRi.Tests.My.MySettings.Default
70 | End Get
71 | End Property
72 | End Module
73 | End Namespace
74 |
--------------------------------------------------------------------------------
/GeometRi.Tests/My Project/Settings.settings:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/GeometRi.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 14
4 | VisualStudioVersion = 14.0.25420.1
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "GeometRi", "GeometRi\GeometRi.vbproj", "{F5D58BD6-DC03-4A0F-9DA3-EE710AD90CAC}"
7 | EndProject
8 | Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "GeometRi.Tests", "GeometRi.Tests\GeometRi.Tests.vbproj", "{6A3E686B-4E54-45CC-9CE0-57FD8304DFCA}"
9 | EndProject
10 | Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "GeometRiExample", "GeometRiExample\GeometRiExample.vbproj", "{1C73CAA1-A41C-44C1-A1BD-2EA51ACFBEED}"
11 | EndProject
12 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GeometRiExample.CSharp", "GeometRiExample.CSharp\GeometRiExample.CSharp.csproj", "{AC37FB79-BBBA-4F6B-9BC2-0B1110936B9E}"
13 | EndProject
14 | Global
15 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
16 | Debug|Any CPU = Debug|Any CPU
17 | Release|Any CPU = Release|Any CPU
18 | EndGlobalSection
19 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
20 | {F5D58BD6-DC03-4A0F-9DA3-EE710AD90CAC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
21 | {F5D58BD6-DC03-4A0F-9DA3-EE710AD90CAC}.Debug|Any CPU.Build.0 = Debug|Any CPU
22 | {F5D58BD6-DC03-4A0F-9DA3-EE710AD90CAC}.Release|Any CPU.ActiveCfg = Release|Any CPU
23 | {F5D58BD6-DC03-4A0F-9DA3-EE710AD90CAC}.Release|Any CPU.Build.0 = Release|Any CPU
24 | {6A3E686B-4E54-45CC-9CE0-57FD8304DFCA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
25 | {6A3E686B-4E54-45CC-9CE0-57FD8304DFCA}.Debug|Any CPU.Build.0 = Debug|Any CPU
26 | {6A3E686B-4E54-45CC-9CE0-57FD8304DFCA}.Release|Any CPU.ActiveCfg = Release|Any CPU
27 | {6A3E686B-4E54-45CC-9CE0-57FD8304DFCA}.Release|Any CPU.Build.0 = Release|Any CPU
28 | {1C73CAA1-A41C-44C1-A1BD-2EA51ACFBEED}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
29 | {1C73CAA1-A41C-44C1-A1BD-2EA51ACFBEED}.Debug|Any CPU.Build.0 = Debug|Any CPU
30 | {1C73CAA1-A41C-44C1-A1BD-2EA51ACFBEED}.Release|Any CPU.ActiveCfg = Release|Any CPU
31 | {1C73CAA1-A41C-44C1-A1BD-2EA51ACFBEED}.Release|Any CPU.Build.0 = Release|Any CPU
32 | {AC37FB79-BBBA-4F6B-9BC2-0B1110936B9E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
33 | {AC37FB79-BBBA-4F6B-9BC2-0B1110936B9E}.Debug|Any CPU.Build.0 = Debug|Any CPU
34 | {AC37FB79-BBBA-4F6B-9BC2-0B1110936B9E}.Release|Any CPU.ActiveCfg = Release|Any CPU
35 | {AC37FB79-BBBA-4F6B-9BC2-0B1110936B9E}.Release|Any CPU.Build.0 = Release|Any CPU
36 | EndGlobalSection
37 | GlobalSection(SolutionProperties) = preSolution
38 | HideSolutionNode = FALSE
39 | EndGlobalSection
40 | EndGlobal
41 |
--------------------------------------------------------------------------------
/GeometRi/GeometRi.vbproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 | {F5D58BD6-DC03-4A0F-9DA3-EE710AD90CAC}
8 | Library
9 |
10 |
11 | GeometRi
12 | GeometRi
13 | 512
14 | Windows
15 | v2.0
16 |
17 |
18 |
19 | AnyCPU
20 | true
21 | full
22 | true
23 | true
24 | bin\Debug\
25 | GeometRi.xml
26 | 42016,41999,42017,42018,42019,42032,42036,42020,42021,42022
27 |
28 |
29 | AnyCPU
30 | pdbonly
31 | false
32 | true
33 | true
34 | bin\Release\
35 | GeometRi.xml
36 | 42016,41999,42017,42018,42019,42032,42036,42020,42021,42022
37 |
38 |
39 | On
40 |
41 |
42 | Binary
43 |
44 |
45 | Off
46 |
47 |
48 | On
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 | True
81 | Application.myapp
82 |
83 |
84 | True
85 | True
86 | Resources.resx
87 |
88 |
89 | True
90 | Settings.settings
91 | True
92 |
93 |
94 |
95 |
96 | VbMyResourcesResXFileCodeGenerator
97 | Resources.Designer.vb
98 | My.Resources
99 | Designer
100 |
101 |
102 |
103 |
104 | MyApplicationCodeGenerator
105 | Application.Designer.vb
106 |
107 |
108 | SettingsSingleFileGenerator
109 | My
110 | Settings.Designer.vb
111 |
112 |
113 |
114 |
121 |
--------------------------------------------------------------------------------
/GeometRi/GeometRi/Circle3D.vb:
--------------------------------------------------------------------------------
1 | Imports System.Math
2 |
3 | Public Class Circle3d
4 |
5 | Implements ICloneable
6 |
7 | Private _point As Point3d
8 | Private _r As Double
9 | Private _normal As Vector3d
10 |
11 | Public Sub New(Center As Point3d, Radius As Double, Normal As Vector3d)
12 | _point = Center.Clone
13 | _r = Radius
14 | _normal = Normal.Clone
15 | End Sub
16 |
17 | Public Sub New(p1 As Point3d, p2 As Point3d, p3 As Point3d)
18 |
19 | Dim v1 As Vector3d = New Vector3d(p1, p2)
20 | Dim v2 As Vector3d = New Vector3d(p1, p3)
21 | If v1.Cross(v2).Norm < GeometRi3D.Tolerance Then
22 | Throw New Exception("Collinear points")
23 | End If
24 |
25 | Dim CS As Coord3d = New Coord3d(p1, v1, v2)
26 | Dim a1 As Point3d = p1.ConvertTo(CS)
27 | Dim a2 As Point3d = p2.ConvertTo(CS)
28 | Dim a3 As Point3d = p3.ConvertTo(CS)
29 |
30 | Dim d1 As Double = a1.X ^ 2 + a1.Y ^ 2
31 | Dim d2 As Double = a2.X ^ 2 + a2.Y ^ 2
32 | Dim d3 As Double = a3.X ^ 2 + a3.Y ^ 2
33 | Dim f As Double = 2.0 * (a1.X * (a2.Y - a3.Y) - a1.Y * (a2.X - a3.X) + a2.X * a3.Y - a3.X * a2.Y)
34 |
35 | Dim X = (d1 * (a2.Y - a3.Y) + d2 * (a3.Y - a1.Y) + d3 * (a1.Y - a2.Y)) / f
36 | Dim Y = (d1 * (a3.X - a2.X) + d2 * (a1.X - a3.X) + d3 * (a2.X - a1.X)) / f
37 | _point = (New Point3d(X, Y, 0, CS)).ConvertTo(p1.Coord)
38 | _r = Sqrt((X - a1.X) ^ 2 + (Y - a1.Y) ^ 2)
39 | _normal = v1.Cross(v2)
40 |
41 | End Sub
42 |
43 | Public Function Clone() As Object Implements ICloneable.Clone
44 | Dim newobj As Circle3d = DirectCast(MemberwiseClone(), Circle3d)
45 | newobj.Center = newobj.Center.Clone
46 | newobj.Normal = newobj.Normal.Clone
47 | Return newobj
48 | End Function
49 |
50 | '''
51 | ''' Center of the circle
52 | '''
53 | Public Property Center As Point3d
54 | Get
55 | Return _point.Clone
56 | End Get
57 | Set(value As Point3d)
58 | _point = value.Clone
59 | End Set
60 | End Property
61 |
62 | '''
63 | ''' Radius of the circle
64 | '''
65 | Public Property R As Double
66 | Get
67 | Return _r
68 | End Get
69 | Set(value As Double)
70 | _r = value
71 | End Set
72 | End Property
73 |
74 | '''
75 | ''' Normal of the circle
76 | '''
77 | Public Property Normal As Vector3d
78 | Get
79 | Return _normal
80 | End Get
81 | Set(value As Vector3d)
82 | _normal = value
83 | End Set
84 | End Property
85 |
86 | Public ReadOnly Property Perimeter As Double
87 | Get
88 | Return 2 * PI * _r
89 | End Get
90 | End Property
91 |
92 | Public ReadOnly Property Area As Double
93 | Get
94 | Return PI * _r ^ 2
95 | End Get
96 | End Property
97 |
98 | Public ReadOnly Property ToEllipse As Ellipse
99 | Get
100 | Dim v1 As Vector3d = _r * _normal.OrthogonalVector.Normalized
101 | Dim v2 As Vector3d = _r * (_normal.Cross(v1)).Normalized
102 | Return New Ellipse(_point, v1, v2)
103 | End Get
104 | End Property
105 |
106 | '''
107 | ''' Returns point on circle for given parameter 't' (0 <= t < 2Pi)
108 | '''
109 | Public Function ParametricForm(t As Double) As Point3d
110 |
111 | ' Get two orthogonal coplanar vectors
112 | Dim v1 As Vector3d = _r * _normal.OrthogonalVector.Normalized
113 | Dim v2 As Vector3d = _r * (_normal.Cross(v1)).Normalized
114 | Return _point + v1.ToPoint * Cos(t) + v2.ToPoint * Sin(t)
115 |
116 | End Function
117 |
118 | '''
119 | ''' Orthogonal projection of the circle to plane
120 | '''
121 | Public Function ProjectionTo(s As Plane3d) As Ellipse
122 | Return Me.ToEllipse.ProjectionTo(s)
123 | End Function
124 |
125 | '''
126 | ''' Intersection of circle with plane.
127 | ''' Returns object of type 'Nothing', 'Circle3d', 'Point3d' or 'Segment3d'.
128 | '''
129 | Public Function IntersectionWith(s As Plane3d) As Object
130 |
131 | If Me.Normal.IsParallelTo(s.Normal) Then
132 |
133 | If Me.Center.BelongsTo(s) Then
134 | ' coplanar objects
135 | Return Me.Clone
136 | Else
137 | ' parallel objects
138 | Return Nothing
139 | End If
140 | Else
141 | Dim l As Line3d = s.IntersectionWith(New Plane3d(Me.Center, Me.Normal))
142 | Dim local_coord As Coord3d = New Coord3d(Me.Center, l.Direction, Me.Normal.Cross(l.Direction))
143 | Dim p As Point3d = l.Point.ConvertTo(local_coord)
144 |
145 | If GeometRi3D.Greater(Abs(p.Y), Me.R) Then
146 | Return Nothing
147 | ElseIf GeometRi3D.AlmostEqual(p.Y, Me.R) Then
148 | Return New Point3d(0, Me.R, 0, local_coord)
149 | ElseIf GeometRi3D.AlmostEqual(p.Y, -Me.R) Then
150 | Return New Point3d(0, -Me.R, 0, local_coord)
151 | Else
152 | Dim d As Double = Sqrt(Me.R ^ 2 - p.Y ^ 2)
153 | Dim p1 = New Point3d(-d, p.Y, 0, local_coord)
154 | Dim p2 = New Point3d(d, p.Y, 0, local_coord)
155 | Return New Segment3d(p1, p2)
156 | End If
157 | End If
158 |
159 | End Function
160 |
161 | #Region "TranslateRotateReflect"
162 | '''
163 | ''' Translate circle by a vector
164 | '''
165 | Public Function Translate(v As Vector3d) As Circle3d
166 | Return New Circle3d(Me.Center.Translate(v), Me.R, Me.Normal)
167 | End Function
168 |
169 | '''
170 | ''' Rotate circle by a given rotation matrix
171 | '''
172 | Public Function Rotate(ByVal m As Matrix3d) As Circle3d
173 | Return New Circle3d(Me.Center.Rotate(m), Me.R, Me.Normal.Rotate(m))
174 | End Function
175 |
176 | '''
177 | ''' Rotate circle by a given rotation matrix around point 'p' as a rotation center
178 | '''
179 | Public Function Rotate(m As Matrix3d, p As Point3d) As Circle3d
180 | Return New Circle3d(Me.Center.Rotate(m, p), Me.R, Me.Normal.Rotate(m))
181 | End Function
182 |
183 | '''
184 | ''' Reflect circle in given point
185 | '''
186 | Public Function ReflectIn(p As Point3d) As Circle3d
187 | Return New Circle3d(Me.Center.ReflectIn(p), Me.R, Me.Normal.ReflectIn(p))
188 | End Function
189 |
190 | '''
191 | ''' Reflect circle in given line
192 | '''
193 | Public Function ReflectIn(l As Line3d) As Circle3d
194 | Return New Circle3d(Me.Center.ReflectIn(l), Me.R, Me.Normal.ReflectIn(l))
195 | End Function
196 |
197 | '''
198 | ''' Reflect circle in given plane
199 | '''
200 | Public Function ReflectIn(s As Plane3d) As Circle3d
201 | Return New Circle3d(Me.Center.ReflectIn(s), Me.R, Me.Normal.ReflectIn(s))
202 | End Function
203 | #End Region
204 |
205 | Public Overloads Overrides Function Equals(obj As Object) As Boolean
206 | If obj Is Nothing OrElse Not Me.GetType() Is obj.GetType() Then
207 | Return False
208 | End If
209 | Dim c As Circle3d = CType(obj, Circle3d)
210 |
211 | Return c.Center = Me.Center AndAlso
212 | Abs(c.R - Me.R) <= GeometRi3D.Tolerance AndAlso
213 | c.Normal.IsParallelTo(Me.Normal)
214 | End Function
215 |
216 | Public Overrides Function GetHashCode() As Integer
217 | Return GeometRi3D.HashFunction(_point.GetHashCode, _r.GetHashCode, _normal.GetHashCode)
218 | End Function
219 |
220 | Public Overloads Function ToString(Optional coord As Coord3d = Nothing) As String
221 |
222 | Dim P As Point3d = _point.ConvertToGlobal
223 | Dim normal As Vector3d = _normal.ConvertToGlobal
224 | If coord IsNot Nothing Then
225 | P = P.ConvertTo(coord)
226 | normal = normal.ConvertTo(coord)
227 | End If
228 |
229 | Dim str As String = String.Format("Circle: ") + vbCrLf
230 | str += String.Format(" Center -> ({0,10:g5}, {1,10:g5}, {2,10:g5})", P.X, P.Y, P.Z) + vbCrLf
231 | str += String.Format(" Radius -> {0,10:g5}", _r) + vbCrLf
232 | str += String.Format(" Normal -> ({0,10:g5}, {1,10:g5}, {2,10:g5})", normal.X, normal.Y, normal.Z)
233 | Return str
234 | End Function
235 |
236 | ' Operators overloads
237 | '-----------------------------------------------------------------
238 |
239 | Public Shared Operator =(c1 As Circle3d, c2 As Circle3d) As Boolean
240 | Return c1.Equals(c2)
241 | End Operator
242 | Public Shared Operator <>(c1 As Circle3d, c2 As Circle3d) As Boolean
243 | Return Not c1.Equals(c2)
244 | End Operator
245 |
246 | End Class
247 |
--------------------------------------------------------------------------------
/GeometRi/GeometRi/Coord3D.vb:
--------------------------------------------------------------------------------
1 | Imports System.Math
2 |
3 | Public Class Coord3d
4 | Implements ICloneable
5 |
6 | Private _origin As Point3d
7 | Private _axes As Matrix3d
8 | Private _name As String
9 | Private Shared count As Integer = 0
10 | Public Shared ReadOnly GlobalCS As Coord3d = New Coord3d("Global_CS")
11 |
12 |
13 | #Region "Constructors"
14 | '''
15 | ''' Create default coordinate system.
16 | '''
17 | ''' Name of the coordinate system.
18 | Public Sub New(Optional name As String = "")
19 | _origin = New Point3d(0, 0, 0)
20 | _axes = Matrix3d.Identity
21 | If (name <> "") Then
22 | _name = name
23 | Else
24 | _name = "Coord " + count.ToString
25 | End If
26 | count += 1
27 | End Sub
28 |
29 | '''
30 | ''' Create coordinate system by origin and transformation matrix.
31 | '''
32 | ''' Origin of the coordinate system.
33 | ''' Transformation matrix.
34 | ''' Name of the coordinate system.
35 | Public Sub New(ByVal p As Point3d, ByVal m As Matrix3d, Optional name As String = "")
36 | If Not m.IsOrthogonal Then
37 | Throw New ArgumentException("The matrix is not orthogonal")
38 | End If
39 |
40 | _origin = p.ConvertToGlobal
41 | _axes = m.Clone
42 | If (name <> "") Then
43 | _name = name
44 | Else
45 | _name = "Coord " + count.ToString
46 | End If
47 | count += 1
48 | End Sub
49 |
50 | '''
51 | ''' Create coordinate system by point and two vectors.
52 | '''
53 | ''' Origin of the coordinate system.
54 | ''' Vector oriented along the X axis.
55 | ''' Vector in the XY plane.
56 | ''' Name of the coordinate system.
57 | Public Sub New(p As Point3d, v1 As Vector3d, v2 As Vector3d, Optional name As String = "")
58 | If v1.IsParallelTo(v2) Then
59 | Throw New Exception("Vectors are parallel")
60 | End If
61 |
62 | v1 = v1.ConvertToGlobal.Normalized
63 | Dim v3 As Vector3d = v1.Cross(v2).Normalized
64 | v2 = v3.Cross(v1).Normalized
65 |
66 | _origin = p.ConvertToGlobal
67 | _axes = New Matrix3d(v1, v2, v3)
68 | If (name <> "") Then
69 | _name = name
70 | Else
71 | _name = "Coord " + count.ToString
72 | End If
73 | count += 1
74 | End Sub
75 |
76 | '''
77 | ''' Create coordinate system by point and two vectors (as Double())
78 | '''
79 | ''' Origin of the coordinate system.
80 | ''' Vector oriented along the X axis.
81 | ''' Vector in the XY plane.
82 | ''' Name of the coordinate system.
83 | Public Sub New(p As Point3d, d1() As Double, d2() As Double, Optional name As String = "")
84 | Dim v1 As New Vector3d(d1)
85 | Dim v2 As New Vector3d(d2)
86 | If v1.IsParallelTo(v2) Then
87 | Throw New Exception("Vectors are parallel")
88 | End If
89 |
90 | v1 = v1.Normalized
91 | Dim v3 As Vector3d = v1.Cross(v2).Normalized
92 | v2 = v3.Cross(v1).Normalized
93 |
94 | _origin = p.ConvertToGlobal
95 | _axes = New Matrix3d(v1, v2, v3)
96 | If (name <> "") Then
97 | _name = name
98 | Else
99 | _name = "Coord " + count.ToString
100 | End If
101 | count += 1
102 | End Sub
103 | #End Region
104 |
105 | Public Function Clone() As Object Implements ICloneable.Clone
106 | Dim newobj As Coord3d = DirectCast(MemberwiseClone(), Coord3d)
107 | newobj.Origin = newobj.Origin.Clone
108 | newobj.Axes = newobj.Axes.Clone
109 | newobj._name = "Coord " + count.ToString
110 | count += 1
111 | Return newobj
112 | End Function
113 |
114 |
115 | '''
116 | ''' Get or Set the origin of the coordinate system
117 | '''
118 | '''
119 | Public Property Origin As Point3d
120 | Get
121 | Return New Point3d(_origin.X, _origin.Y, _origin.Z)
122 | End Get
123 | Set(value As Point3d)
124 | _origin = value.ConvertToGlobal
125 | End Set
126 | End Property
127 | '''
128 | ''' Get or Set unit vectors of the axes, stored as row-matrix(3x3)
129 | '''
130 | '''
131 | Public Property Axes As Matrix3d
132 | Get
133 | Return _axes.Clone
134 | End Get
135 | Set(value As Matrix3d)
136 | If value.IsOrthogonal Then
137 | _axes = value.Clone
138 | Else
139 | Throw New ArgumentException("The matrix is not orthogonal")
140 | End If
141 | End Set
142 | End Property
143 |
144 | Public ReadOnly Property Name As String
145 | Get
146 | Return _name
147 | End Get
148 | End Property
149 |
150 | '''
151 | ''' Get total number of defined coordinate systems
152 | '''
153 | Public Shared ReadOnly Property Counts As Integer
154 | Get
155 | Return count
156 | End Get
157 | End Property
158 |
159 |
160 | '''
161 | ''' Get X-axis
162 | '''
163 | Public ReadOnly Property Xaxis As Vector3d
164 | Get
165 | Return _axes.Row1
166 | End Get
167 | End Property
168 | '''
169 | ''' Get Y-axis
170 | '''
171 | Public ReadOnly Property Yaxis As Vector3d
172 | Get
173 | Return _axes.Row2
174 | End Get
175 | End Property
176 | '''
177 | ''' Get Z-axis
178 | '''
179 | Public ReadOnly Property Zaxis As Vector3d
180 | Get
181 | Return _axes.Row3
182 | End Get
183 | End Property
184 |
185 | '''
186 | ''' XY plane in the current coordinate system
187 | '''
188 | Public ReadOnly Property XY_plane As Plane3d
189 | Get
190 | Return New Plane3d(0, 0, 1, 0, Me)
191 | End Get
192 | End Property
193 |
194 | '''
195 | ''' XZ plane in the current coordinate system
196 | '''
197 | Public ReadOnly Property XZ_plane As Plane3d
198 | Get
199 | Return New Plane3d(0, 1, 0, 0, Me)
200 | End Get
201 | End Property
202 |
203 | '''
204 | ''' YZ plane in the current coordinate system
205 | '''
206 | Public ReadOnly Property YZ_plane As Plane3d
207 | Get
208 | Return New Plane3d(1, 0, 0, 0, Me)
209 | End Get
210 | End Property
211 |
212 | '''
213 | ''' Rotate coordinate system around rotation axis
214 | '''
215 | ''' Rotation axis
216 | ''' Rotation angle (radians, counterclockwise)
217 | Public Sub Rotate(axis As Vector3d, angle As Double)
218 | _axes = _axes * Matrix3d.RotationMatrix(axis.ConvertToGlobal, angle).Transpose
219 | End Sub
220 |
221 | '''
222 | ''' Rotate coordinate system around rotation axis
223 | '''
224 | ''' Rotation axis
225 | ''' Rotation angle (degrees, counterclockwise)
226 | Public Sub RotateDeg(axis As Vector3d, angle As Double)
227 | _axes = _axes * Matrix3d.RotationMatrix(axis.ConvertToGlobal, angle * PI / 180).Transpose
228 | End Sub
229 |
230 |
231 | Public Overloads Overrides Function Equals(obj As Object) As Boolean
232 | If obj Is Nothing OrElse Not Me.GetType() Is obj.GetType() Then
233 | Return False
234 | End If
235 | Dim cs As Coord3d = CType(obj, Coord3d)
236 | Return Me._name = cs._name
237 | End Function
238 |
239 | Public Overrides Function GetHashCode() As Integer
240 | Return _name.GetHashCode
241 | End Function
242 |
243 | Public Overrides Function ToString() As String
244 | Dim str As New System.Text.StringBuilder
245 | str.Append("Coord3d: " + _name + vbCrLf)
246 | str.Append(String.Format("Origin -> X: {0,10:g5}, Y: {1,10:g5}, Z: {2,10:g5}", _origin.X, _origin.Y, _origin.Z) + vbCrLf)
247 | str.Append(String.Format("Xaxis -> ({0,10:g5}, {1,10:g5}, {2,10:g5})", Xaxis.X, Xaxis.Y, Xaxis.Z) + vbCrLf)
248 | str.Append(String.Format("Yaxis -> ({0,10:g5}, {1,10:g5}, {2,10:g5})", Yaxis.X, Yaxis.Y, Yaxis.Z) + vbCrLf)
249 | str.Append(String.Format("Zaxis -> ({0,10:g5}, {1,10:g5}, {2,10:g5})", Zaxis.X, Zaxis.Y, Zaxis.Z))
250 | Return str.ToString
251 | End Function
252 |
253 | ' Operators overloads
254 | '-----------------------------------------------------------------
255 | Public Shared Operator =(c1 As Coord3d, c2 As Coord3d) As Boolean
256 | If c1 IsNot Nothing Then
257 | Return c1.Equals(c2)
258 | ElseIf c1 Is Nothing AndAlso c2 Is Nothing Then
259 | Return True
260 | Else
261 | Return False
262 | End If
263 | End Operator
264 | Public Shared Operator <>(c1 As Coord3d, c2 As Coord3d) As Boolean
265 | If c1 IsNot Nothing Then
266 | Return Not c1.Equals(c2)
267 | ElseIf c1 Is Nothing AndAlso c2 Is Nothing Then
268 | Return False
269 | Else
270 | Return True
271 | End If
272 | End Operator
273 |
274 | End Class
275 |
--------------------------------------------------------------------------------
/GeometRi/GeometRi/Ellipse.vb:
--------------------------------------------------------------------------------
1 | Imports System.Math
2 |
3 | Public Class Ellipse
4 |
5 | Implements ICloneable
6 |
7 | Private _point As Point3d
8 | Private _v1 As Vector3d
9 | Private _v2 As Vector3d
10 |
11 | Public Sub New(Center As Point3d, semiaxis_a As Vector3d, semiaxis_b As Vector3d)
12 | If (Not semiaxis_a.IsOrthogonalTo(semiaxis_b)) Then
13 | Throw New Exception("Semiaxes are not orthogonal")
14 | End If
15 | _point = Center.Clone
16 | If semiaxis_a.Norm >= semiaxis_b.Norm Then
17 | _v1 = semiaxis_a.Clone
18 | _v2 = semiaxis_b.Clone
19 | Else
20 | _v1 = semiaxis_b.Clone
21 | _v2 = semiaxis_a.Clone
22 | End If
23 |
24 | End Sub
25 |
26 | Public Function Clone() As Object Implements ICloneable.Clone
27 | Return New Ellipse(_point.Clone, _v1.Clone, _v2.Clone)
28 | End Function
29 |
30 | #Region "Properties"
31 | Public ReadOnly Property Center As Point3d
32 | Get
33 | Return _point.Clone
34 | End Get
35 | End Property
36 |
37 | Public ReadOnly Property MajorSemiaxis As Vector3d
38 | Get
39 | Return _v1.Clone
40 | End Get
41 | End Property
42 |
43 | Public ReadOnly Property MinorSemiaxis As Vector3d
44 | Get
45 | Return _v2.Clone
46 | End Get
47 | End Property
48 |
49 | Public ReadOnly Property Normal As Vector3d
50 | Get
51 | Return _v1.Cross(_v2)
52 | End Get
53 | End Property
54 |
55 | '''
56 | ''' Length of the major semiaxis
57 | '''
58 | Public ReadOnly Property A As Double
59 | Get
60 | Return _v1.Norm
61 | End Get
62 | End Property
63 |
64 | '''
65 | ''' Length of the minor semiaxis
66 | '''
67 | Public ReadOnly Property B As Double
68 | Get
69 | Return _v2.Norm
70 | End Get
71 | End Property
72 |
73 | '''
74 | ''' Distance from center to focus
75 | '''
76 | Public ReadOnly Property F As Double
77 | Get
78 | Return Sqrt(_v1.Norm ^ 2 - _v2.Norm ^ 2)
79 | End Get
80 | End Property
81 |
82 | '''
83 | ''' First focus
84 | '''
85 | Public ReadOnly Property F1 As Point3d
86 | Get
87 | Return _point.Translate(F * _v1.Normalized)
88 | End Get
89 | End Property
90 |
91 | '''
92 | ''' Second focus
93 | '''
94 | Public ReadOnly Property F2 As Point3d
95 | Get
96 | Return _point.Translate(-F * _v1.Normalized)
97 | End Get
98 | End Property
99 |
100 | '''
101 | ''' Eccentricity of the ellipse
102 | '''
103 | Public ReadOnly Property e As Double
104 | Get
105 | Return Sqrt(1 - _v2.Norm ^ 2 / _v1.Norm ^ 2)
106 | End Get
107 | End Property
108 |
109 | Public ReadOnly Property Area As Double
110 | Get
111 | Return PI * A * B
112 | End Get
113 | End Property
114 |
115 | '''
116 | ''' Approximate circumference of the ellipse
117 | '''
118 | Public ReadOnly Property Perimeter As Double
119 | Get
120 | Dim a As Double = _v1.Norm
121 | Dim b As Double = _v2.Norm
122 | Dim h As Double = (a - b) ^ 2 / (a + b) ^ 2
123 | Return PI * (a + b) * (1 + 3 * h / (10 + Sqrt(4 - 3 * h)))
124 | End Get
125 | End Property
126 | #End Region
127 |
128 | '''
129 | ''' Returns point on ellipse for given parameter 't' (0 <= t < 2Pi)
130 | '''
131 | Public Function ParametricForm(t As Double) As Point3d
132 |
133 | Return _point + _v1.ToPoint * Cos(t) + _v2.ToPoint * Sin(t)
134 |
135 | End Function
136 |
137 | '''
138 | ''' Orthogonal projection of the ellipse to plane
139 | '''
140 | Public Function ProjectionTo(s As Plane3d) As Ellipse
141 |
142 | Dim c As Point3d = _point.ProjectionTo(s)
143 | Dim q As Point3d = _point.Translate(_v1).ProjectionTo(s)
144 | Dim p As Point3d = _point.Translate(_v2).ProjectionTo(s)
145 |
146 | Dim f1 = New Vector3d(c, p)
147 | Dim f2 = New Vector3d(c, q)
148 |
149 | Dim t0 As Double = 0.5 * Atan2(2 * f1 * f2, f1 * f1 - f2 * f2)
150 | Dim v1 As Vector3d = f1 * Cos(t0) + f2 * Sin(t0)
151 | Dim v2 As Vector3d = f1 * Cos(t0 + PI / 2) + f2 * Sin(t0 + PI / 2)
152 |
153 | Return New Ellipse(c, v1, v2)
154 | End Function
155 |
156 | '''
157 | ''' Intersection of ellipse with plane.
158 | ''' Returns object of type 'Nothing', 'Ellipse', 'Point3d' or 'Segment3d'.
159 | '''
160 | Public Function IntersectionWith(s As Plane3d) As Object
161 |
162 | If Me.Normal.IsParallelTo(s.Normal) Then
163 |
164 | If Me.Center.BelongsTo(s) Then
165 | ' coplanar objects
166 | Return Me.Clone
167 | Else
168 | ' parallel objects
169 | Return Nothing
170 | End If
171 | Else
172 | Dim l As Line3d = s.IntersectionWith(New Plane3d(Me.Center, Me.Normal))
173 | Dim local_coord As Coord3d = New Coord3d(Me.Center, Me._v1, Me._v2)
174 | Dim p As Point3d = l.Point.ConvertTo(local_coord)
175 | Dim v As Vector3d = l.Direction.ConvertTo(local_coord)
176 | Dim a As Double = Me.A
177 | Dim b As Double = Me.B
178 |
179 | If Abs(v.Y / v.X) > 100 Then
180 | ' line is almost vertical, rotate local coord
181 | local_coord = New Coord3d(Me.Center, Me._v2, Me._v1)
182 | p = l.Point.ConvertTo(local_coord)
183 | v = l.Direction.ConvertTo(local_coord)
184 | a = Me.B
185 | b = Me.A
186 | End If
187 |
188 | ' Find intersection of line and ellipse (2D)
189 | ' Solution from: http://www.ambrsoft.com/TrigoCalc/Circles2/Ellipse/EllipseLine.htm
190 |
191 | ' Line equation in form: y = mx + c
192 | Dim m As Double = v.Y / v.X
193 | Dim c As Double = p.Y - m * p.X
194 |
195 | Dim amb As Double = a ^ 2 * m ^ 2 + b ^ 2
196 | Dim det As Double = amb - c ^ 2
197 | If det < -GeometRi3D.Tolerance Then
198 | Return Nothing
199 | ElseIf GeometRi3D.AlmostEqual(det, 0) Then
200 | Dim x As Double = -a ^ 2 * m * c / amb
201 | Dim y As Double = b ^ 2 * c / amb
202 | Return New Point3d(x, y, 0, local_coord)
203 | Else
204 | Dim x1 As Double = (-a ^ 2 * m * c + a * b * Sqrt(det)) / amb
205 | Dim x2 As Double = (-a ^ 2 * m * c - a * b * Sqrt(det)) / amb
206 | Dim y1 As Double = (b ^ 2 * c + a * b * m * Sqrt(det)) / amb
207 | Dim y2 As Double = (b ^ 2 * c - a * b * m * Sqrt(det)) / amb
208 | Return New Segment3d(New Point3d(x1, y1, 0, local_coord), New Point3d(x2, y2, 0, local_coord))
209 | End If
210 | End If
211 |
212 | End Function
213 |
214 | #Region "TranslateRotateReflect"
215 | '''
216 | ''' Translate ellipse by a vector
217 | '''
218 | Public Function Translate(v As Vector3d) As Ellipse
219 | Return New Ellipse(Me.Center.Translate(v), _v1, _v2)
220 | End Function
221 |
222 | '''
223 | ''' Rotate ellipse by a given rotation matrix
224 | '''
225 | Public Function Rotate(ByVal m As Matrix3d) As Ellipse
226 | Return New Ellipse(Me.Center.Rotate(m), _v1.Rotate(m), _v2.Rotate(m))
227 | End Function
228 |
229 | '''
230 | ''' Rotate ellipse by a given rotation matrix around point 'p' as a rotation center
231 | '''
232 | Public Function Rotate(m As Matrix3d, p As Point3d) As Ellipse
233 | Return New Ellipse(Me.Center.Rotate(m, p), _v1.Rotate(m), _v2.Rotate(m))
234 | End Function
235 |
236 | '''
237 | ''' Reflect ellipse in given point
238 | '''
239 | Public Function ReflectIn(p As Point3d) As Ellipse
240 | Return New Ellipse(Me.Center.ReflectIn(p), _v1.ReflectIn(p), _v2.ReflectIn(p))
241 | End Function
242 |
243 | '''
244 | ''' Reflect ellipse in given line
245 | '''
246 | Public Function ReflectIn(l As Line3d) As Ellipse
247 | Return New Ellipse(Me.Center.ReflectIn(l), _v1.ReflectIn(l), _v2.ReflectIn(l))
248 | End Function
249 |
250 | '''
251 | ''' Reflect ellipse in given plane
252 | '''
253 | Public Function ReflectIn(s As Plane3d) As Ellipse
254 | Return New Ellipse(Me.Center.ReflectIn(s), _v1.ReflectIn(s), _v2.ReflectIn(s))
255 | End Function
256 | #End Region
257 |
258 | Public Overloads Overrides Function Equals(obj As Object) As Boolean
259 | If obj Is Nothing OrElse Not Me.GetType() Is obj.GetType() Then
260 | Return False
261 | End If
262 | Dim e As Ellipse = CType(obj, Ellipse)
263 |
264 | If GeometRi3D.AlmostEqual(Me.A, Me.B) Then
265 | ' Ellipse is circle
266 | If GeometRi3D.AlmostEqual(e.A, e.B) Then
267 | ' Second ellipse also circle
268 | Return Me.Center = e.Center AndAlso
269 | GeometRi3D.AlmostEqual(Me.A, e.A) AndAlso
270 | e.Normal.IsParallelTo(Me.Normal)
271 | Else
272 | Return False
273 | End If
274 | Else
275 | Return Me.Center = e.Center AndAlso
276 | GeometRi3D.AlmostEqual(Me.A, e.A) AndAlso
277 | GeometRi3D.AlmostEqual(Me.B, e.B) AndAlso
278 | e.MajorSemiaxis.IsParallelTo(Me.MajorSemiaxis) AndAlso
279 | e.MinorSemiaxis.IsParallelTo(Me.MinorSemiaxis)
280 | End If
281 | End Function
282 |
283 | Public Overrides Function GetHashCode() As Integer
284 | Return GeometRi3D.HashFunction(_point.GetHashCode, _v1.GetHashCode, _v2.GetHashCode)
285 | End Function
286 |
287 | Public Overloads Function ToString(Optional coord As Coord3d = Nothing) As String
288 |
289 | Dim P As Point3d = _point.ConvertToGlobal
290 | Dim v1 As Vector3d = _v1.ConvertToGlobal
291 | Dim v2 As Vector3d = _v2.ConvertToGlobal
292 | If coord IsNot Nothing Then
293 | P = P.ConvertTo(coord)
294 | v1 = v1.ConvertTo(coord)
295 | v2 = v2.ConvertTo(coord)
296 | End If
297 |
298 | Dim str As String = String.Format("Ellipse: ") + vbCrLf
299 | str += String.Format(" Center -> ({0,10:g5}, {1,10:g5}, {2,10:g5})", P.X, P.Y, P.Z) + vbCrLf
300 | str += String.Format(" Semiaxis A -> ({0,10:g5}, {1,10:g5}, {2,10:g5})", v1.X, v1.Y, v1.Z) + vbCrLf
301 | str += String.Format(" Semiaxis B -> ({0,10:g5}, {1,10:g5}, {2,10:g5})", v2.X, v2.Y, v2.Z) + vbCrLf
302 | Return str
303 | End Function
304 |
305 | ' Operators overloads
306 | '-----------------------------------------------------------------
307 |
308 | Public Shared Operator =(c1 As Ellipse, c2 As Ellipse) As Boolean
309 | Return c1.Equals(c2)
310 | End Operator
311 | Public Shared Operator <>(c1 As Ellipse, c2 As Ellipse) As Boolean
312 | Return Not c1.Equals(c2)
313 | End Operator
314 |
315 | End Class
316 |
--------------------------------------------------------------------------------
/GeometRi/GeometRi/GeometRi3D.vb:
--------------------------------------------------------------------------------
1 | Public MustInherit Class GeometRi3D
2 |
3 | Private Shared _tolerance As Double = 0.000000000001
4 |
5 | '''
6 | ''' Tolerance used for comparison operations (default 1e-12)
7 | '''
8 | Public Shared Property Tolerance As Double
9 | Get
10 | Return _tolerance
11 | End Get
12 | Set(value As Double)
13 | _tolerance = value
14 | End Set
15 | End Property
16 |
17 | '''
18 | ''' Tolerance based equality check
19 | '''
20 | Public Shared Function AlmostEqual(a As Double, b As Double) As Boolean
21 | If Math.Abs(a - b) <= _tolerance Then
22 | Return True
23 | Else
24 | Return False
25 | End If
26 | End Function
27 |
28 | '''
29 | ''' Tolerance based unequality check
30 | '''
31 | Public Shared Function NotEqual(a As Double, b As Double) As Boolean
32 | If Math.Abs(a - b) > _tolerance Then
33 | Return True
34 | Else
35 | Return False
36 | End If
37 | End Function
38 |
39 | '''
40 | ''' Tolerance based comparison
41 | '''
42 | Public Shared Function Greater(a As Double, b As Double) As Boolean
43 | If (a - b) > _tolerance Then
44 | Return True
45 | Else
46 | Return False
47 | End If
48 | End Function
49 |
50 | '''
51 | ''' Tolerance based comparison
52 | '''
53 | Public Shared Function Smaller(a As Double, b As Double) As Boolean
54 | If (a - b) < -_tolerance Then
55 | Return True
56 | Else
57 | Return False
58 | End If
59 | End Function
60 |
61 | Friend Shared Function HashFunction(n1 As Integer, n2 As Integer) As Integer
62 | Return (n1 << 4) Xor (n1 >> 28) Xor n2
63 | End Function
64 |
65 | Friend Shared Function HashFunction(n1 As Integer, n2 As Integer, n3 As Integer) As Integer
66 | n1 = (n1 << 4) Xor (n1 >> 28) Xor n2
67 | Return (n1 << 4) Xor (n1 >> 28) Xor n3
68 | End Function
69 |
70 | Friend Shared Function HashFunction(n1 As Integer, n2 As Integer, n3 As Integer, n4 As Integer) As Integer
71 | n1 = (n1 << 4) Xor (n1 >> 28) Xor n2
72 | n1 = (n1 << 4) Xor (n1 >> 28) Xor n3
73 | Return (n1 << 4) Xor (n1 >> 28) Xor n4
74 | End Function
75 |
76 |
77 | End Class
78 |
--------------------------------------------------------------------------------
/GeometRi/GeometRi/Line3D.vb:
--------------------------------------------------------------------------------
1 | Imports System.Math
2 |
3 | Public Class Line3d
4 |
5 | Implements ICloneable
6 |
7 | Private _point As Point3d
8 | Private _dir As Vector3d
9 |
10 | #Region "Constructors"
11 | '''
12 | ''' Create default line.
13 | '''
14 | Public Sub New()
15 | _point = New Point3d()
16 | _dir = New Vector3d(1, 0, 0)
17 | End Sub
18 |
19 | '''
20 | ''' Create line by point and dirction.
21 | '''
22 | ''' Point on the line.
23 | ''' Direction vector.
24 | Public Sub New(ByVal p As Point3d, ByVal v As Vector3d)
25 | _point = p.Clone
26 | _dir = v.Clone
27 | End Sub
28 |
29 | '''
30 | ''' Create line by two points.
31 | '''
32 | ''' First point.
33 | ''' Second point.
34 | Public Sub New(ByVal p1 As Point3d, ByVal p2 As Point3d)
35 | _point = p1.Clone
36 | _dir = New Vector3d(p1, p2)
37 | End Sub
38 | #End Region
39 |
40 |
41 | Public Function Clone() As Object Implements ICloneable.Clone
42 | Dim newobj As Line3d = DirectCast(MemberwiseClone(), Line3d)
43 | newobj.Point = newobj.Point.Clone
44 | newobj.Direction = newobj.Direction.Clone
45 | Return newobj
46 | End Function
47 |
48 | '''
49 | ''' Base point of the line
50 | '''
51 | '''
52 | Public Property Point As Point3d
53 | Get
54 | Return _point.Clone
55 | End Get
56 | Set(value As Point3d)
57 | _point = value.Clone
58 | End Set
59 | End Property
60 |
61 | '''
62 | ''' Direction vector of the line
63 | '''
64 | '''
65 | Public Property Direction As Vector3d
66 | Get
67 | Return _dir.Clone
68 | End Get
69 | Set(value As Vector3d)
70 | _dir = value.Clone
71 | End Set
72 | End Property
73 |
74 | #Region "DistanceTo"
75 | '''
76 | ''' Shortest distance between line and point
77 | '''
78 | Public Function DistanceTo(p As Point3d) As Double
79 | Return p.DistanceTo(Me)
80 | End Function
81 |
82 | '''
83 | ''' Shortest distance between line and ray
84 | '''
85 | Public Function DistanceTo(r As Ray3d) As Double
86 | Return r.DistanceTo(Me)
87 | End Function
88 |
89 | '''
90 | ''' Shortest distance between line and segment
91 | '''
92 | Public Function DistanceTo(s As Segment3d) As Double
93 | Return s.DistanceTo(Me)
94 | End Function
95 |
96 | '''
97 | ''' Shortest distance between two lines
98 | '''
99 | Public Overridable Function DistanceTo(l As Line3d) As Double
100 | Dim r1 As Vector3d = Me.Point.ToVector
101 | Dim r2 As Vector3d = l.Point.ToVector
102 | Dim s1 As Vector3d = Me.Direction
103 | Dim s2 As Vector3d = l.Direction
104 | If s1.Cross(s2).Norm > GeometRi3D.Tolerance Then
105 | ' Crossing lines
106 | Return Abs((r2 - r1) * s1.Cross(s2)) / s1.Cross(s2).Norm
107 | Else
108 | ' Parallel lines
109 | Return (r2 - r1).Cross(s1).Norm / s1.Norm
110 | End If
111 | End Function
112 | #End Region
113 |
114 |
115 | '''
116 | ''' Point on the perpendicular to the second line
117 | '''
118 | Public Overridable Function PerpendicularTo(l As Line3d) As Point3d
119 | Dim r1 As Vector3d = Me.Point.ToVector
120 | Dim r2 As Vector3d = l.Point.ToVector
121 | Dim s1 As Vector3d = Me.Direction
122 | Dim s2 As Vector3d = l.Direction
123 | If s1.Cross(s2).Norm > GeometRi3D.Tolerance Then
124 | r1 = r2 + (r2 - r1) * s1.Cross(s1.Cross(s2)) / (s1 * s2.Cross(s1.Cross(s2))) * s2
125 | Return r1.ToPoint
126 | Else
127 | Throw New Exception("Lines are parallel")
128 | End If
129 | End Function
130 |
131 | '''
132 | ''' Get intersection of line with plane.
133 | ''' Returns object of type 'Nothing', 'Point3d' or 'Line3d'.
134 | '''
135 | Public Overridable Function IntersectionWith(s As Plane3d) As Object
136 | Dim r1 As Vector3d = Me.Point.ToVector
137 | Dim s1 As Vector3d = Me.Direction
138 | Dim n2 As Vector3d = s.Normal
139 | If Abs(s1 * n2) < GeometRi3D.Tolerance Then
140 | ' Line and plane are parallel
141 | If Me.Point.BelongsTo(s) Then
142 | ' Line lies in the plane
143 | Return Me
144 | Else
145 | Return Nothing
146 | End If
147 | Else
148 | ' Intersection point
149 | s.SetCoord(r1.Coord)
150 | r1 = r1 - ((r1 * n2) + s.D) / (s1 * n2) * s1
151 | Return r1.ToPoint
152 | End If
153 | End Function
154 |
155 | '''
156 | ''' Get intersection of line with sphere.
157 | ''' Returns object of type 'Nothing', 'Point3d' or 'Segment3d'.
158 | '''
159 | Public Function IntersectionWith(s As Sphere) As Object
160 | Return s.IntersectionWith(Me)
161 | End Function
162 |
163 | '''
164 | ''' Get the orthogonal projection of a line to the plane.
165 | ''' Return object of type 'Line3d' or 'Point3d'
166 | '''
167 | Public Overridable Function ProjectionTo(s As Plane3d) As Object
168 | Dim n1 As Vector3d = s.Normal
169 | Dim n2 As Vector3d = Me.Direction.Cross(n1)
170 | If n2.Norm < GeometRi3D.Tolerance Then
171 | ' Line is perpendicular to the plane
172 | Return Me.Point.ProjectionTo(s)
173 | Else
174 | Return New Line3d(Me.Point.ProjectionTo(s), n1.Cross(n2))
175 | End If
176 | End Function
177 |
178 | #Region "AngleTo"
179 | '''
180 | ''' Smalest angle between two lines in radians (0 < angle < Pi/2)
181 | '''
182 | Public Function AngleTo(l As Line3d) As Double
183 | Dim ang As Double = Me.Direction.AngleTo(l)
184 | If ang <= PI / 2 Then
185 | Return ang
186 | Else
187 | Return PI - ang
188 | End If
189 | End Function
190 | '''
191 | ''' Smalest angle between two lines in degrees (0 < angle < 90)
192 | '''
193 | Public Function AngleToDeg(l As Line3d) As Double
194 | Return AngleTo(l) * 180 / PI
195 | End Function
196 |
197 | '''
198 | ''' Smallest angle between line and plane in radians (0 < angle < Pi/2)
199 | '''
200 | Public Function AngleTo(s As Plane3d) As Double
201 | Dim ang As Double = Asin(Me.Direction.Dot(s.Normal) / Me.Direction.Norm / s.Normal.Norm)
202 | Return Abs(ang)
203 | End Function
204 | '''
205 | ''' Smallest angle line and plane in degrees (0 < angle < 90)
206 | '''
207 | Public Function AngleToDeg(s As Plane3d) As Double
208 | Return AngleTo(s) * 180 / PI
209 | End Function
210 | #End Region
211 |
212 |
213 | #Region "TranslateRotateReflect"
214 | '''
215 | ''' Translate line by a vector
216 | '''
217 | Public Overridable Function Translate(v As Vector3d) As Line3d
218 | Dim l As Line3d = Me.Clone
219 | l.Point = l.Point.Translate(v)
220 | Return l
221 | End Function
222 |
223 | '''
224 | ''' Rotate line by a given rotation matrix
225 | '''
226 | Public Overridable Function Rotate(ByVal m As Matrix3d) As Line3d
227 | Dim l As Line3d = Me.Clone
228 | l.Point = l.Point.Rotate(m)
229 | l.Direction = l.Direction.Rotate(m)
230 | Return l
231 | End Function
232 |
233 | '''
234 | ''' Rotate line by a given rotation matrix around point 'p' as a rotation center
235 | '''
236 | Public Overridable Function Rotate(m As Matrix3d, p As Point3d) As Line3d
237 | Dim l As Line3d = Me.Clone
238 | l.Point = l.Point.Rotate(m, p)
239 | l.Direction = l.Direction.Rotate(m)
240 | Return l
241 | End Function
242 |
243 | '''
244 | ''' Reflect line in given point
245 | '''
246 | Public Overridable Function ReflectIn(p As Point3d) As Line3d
247 | Return New Line3d(Me.Point.ReflectIn(p), Me.Direction.ReflectIn(p))
248 | End Function
249 |
250 | '''
251 | ''' Reflect line in given line
252 | '''
253 | Public Overridable Function ReflectIn(l As Line3d) As Line3d
254 | Return New Line3d(Me.Point.ReflectIn(l), Me.Direction.ReflectIn(l))
255 | End Function
256 |
257 | '''
258 | ''' Reflect line in given plane
259 | '''
260 | Public Overridable Function ReflectIn(s As Plane3d) As Line3d
261 | Return New Line3d(Me.Point.ReflectIn(s), Me.Direction.ReflectIn(s))
262 | End Function
263 | #End Region
264 |
265 | Public Overloads Overrides Function Equals(obj As Object) As Boolean
266 | If obj Is Nothing OrElse Not Me.GetType() Is obj.GetType() Then
267 | Return False
268 | End If
269 | Dim l As Line3d = CType(obj, Line3d)
270 | Return Me.Point.BelongsTo(l) AndAlso Me.Direction.IsParallelTo(l.Direction)
271 | End Function
272 |
273 | Public Overrides Function GetHashCode() As Integer
274 | Return GeometRi3D.HashFunction(_point.GetHashCode, _dir.GetHashCode)
275 | End Function
276 |
277 | Public Overloads Function ToString(Optional coord As Coord3d = Nothing) As String
278 | Dim str As New System.Text.StringBuilder
279 | Dim P As Point3d = _point.ConvertToGlobal
280 | Dim dir As Vector3d = _dir.ConvertToGlobal
281 | If coord IsNot Nothing Then
282 | P = _point.ConvertTo(coord)
283 | dir = _dir.ConvertTo(coord)
284 | End If
285 | str.Append("Line:" + vbCrLf)
286 | str.Append(String.Format("Point -> ({0,10:g5}, {1,10:g5}, {2,10:g5})", P.X, P.Y, P.Z) + vbCrLf)
287 | str.Append(String.Format("Direction -> ({0,10:g5}, {1,10:g5}, {2,10:g5})", dir.X, dir.Y, dir.Z))
288 | Return str.ToString
289 | End Function
290 |
291 | ' Operators overloads
292 | '-----------------------------------------------------------------
293 | Public Shared Operator =(l1 As Line3d, l2 As Line3d) As Boolean
294 | Return l1.Equals(l2)
295 | End Operator
296 | Public Shared Operator <>(l1 As Line3d, l2 As Line3d) As Boolean
297 | Return Not l1.Equals(l2)
298 | End Operator
299 |
300 | End Class
301 |
--------------------------------------------------------------------------------
/GeometRi/GeometRi/Matrix3D.vb:
--------------------------------------------------------------------------------
1 | Imports System.Math
2 |
3 | Public Class Matrix3d
4 |
5 | Implements ICloneable
6 |
7 | Public val(2, 2) As Double
8 |
9 | Public Sub New()
10 | For i As Integer = 0 To 2
11 | For j As Integer = 0 To 2
12 | Me.val(i, j) = 0.0
13 | Next
14 | Next
15 | End Sub
16 | Public Sub New(ByVal r1 As Vector3d, ByVal r2 As Vector3d, ByVal r3 As Vector3d)
17 | Row1 = r1
18 | Row2 = r2
19 | Row3 = r3
20 | End Sub
21 | Public Sub New(ByVal v1() As Double, ByVal v2() As Double, ByVal v3() As Double)
22 | Row1 = New Vector3d(v1)
23 | Row2 = New Vector3d(v2)
24 | Row3 = New Vector3d(v3)
25 | End Sub
26 |
27 | Public Shared Function Identity() As Matrix3d
28 | Dim I As Matrix3d = New Matrix3d()
29 | I(0, 0) = 1.0
30 | I(1, 1) = 1.0
31 | I(2, 2) = 1.0
32 | Return I
33 | End Function
34 |
35 | Public Function Clone() As Object Implements ICloneable.Clone
36 | Dim newm As Matrix3d = DirectCast(MemberwiseClone(), Matrix3d)
37 | newm.val = newm.val.Clone
38 | Return newm
39 | End Function
40 |
41 | Default Public Property Item(i As Integer, j As Integer) As Double
42 | Get
43 | Return val(i, j)
44 | End Get
45 | Set(value As Double)
46 | val(i, j) = value
47 | End Set
48 | End Property
49 |
50 | Public Property Row1 As Vector3d
51 | Get
52 | Return New Vector3d(val(0, 0), val(0, 1), val(0, 2))
53 | End Get
54 | Set(value As Vector3d)
55 | val(0, 0) = value.X
56 | val(0, 1) = value.Y
57 | val(0, 2) = value.Z
58 | End Set
59 | End Property
60 | Public Property Row2 As Vector3d
61 | Get
62 | Return New Vector3d(val(1, 0), val(1, 1), val(1, 2))
63 | End Get
64 | Set(value As Vector3d)
65 | val(1, 0) = value.X
66 | val(1, 1) = value.Y
67 | val(1, 2) = value.Z
68 | End Set
69 | End Property
70 | Public Property Row3 As Vector3d
71 | Get
72 | Return New Vector3d(val(2, 0), val(2, 1), val(2, 2))
73 | End Get
74 | Set(value As Vector3d)
75 | val(2, 0) = value.X
76 | val(2, 1) = value.Y
77 | val(2, 2) = value.Z
78 | End Set
79 | End Property
80 |
81 | Public Property Column1 As Vector3d
82 | Get
83 | Return New Vector3d(val(0, 0), val(1, 0), val(2, 0))
84 | End Get
85 | Set(value As Vector3d)
86 | val(0, 0) = value.X
87 | val(1, 0) = value.Y
88 | val(2, 0) = value.Z
89 | End Set
90 | End Property
91 | Public Property Column2 As Vector3d
92 | Get
93 | Return New Vector3d(val(0, 1), val(1, 1), val(2, 1))
94 | End Get
95 | Set(value As Vector3d)
96 | val(0, 1) = value.X
97 | val(1, 1) = value.Y
98 | val(2, 1) = value.Z
99 | End Set
100 | End Property
101 | Public Property Column3 As Vector3d
102 | Get
103 | Return New Vector3d(val(0, 2), val(1, 2), val(2, 2))
104 | End Get
105 | Set(value As Vector3d)
106 | val(0, 2) = value.X
107 | val(1, 2) = value.Y
108 | val(2, 2) = value.Z
109 | End Set
110 | End Property
111 |
112 | '''
113 | ''' Determinant of the matrix
114 | '''
115 | Public ReadOnly Property Det As Double
116 | Get
117 | Det = val(0, 0) * (val(1, 1) * val(2, 2) - val(1, 2) * val(2, 1)) -
118 | val(0, 1) * (val(1, 0) * val(2, 2) - val(1, 2) * val(2, 0)) +
119 | val(0, 2) * (val(1, 0) * val(2, 1) - val(1, 1) * val(2, 0))
120 | End Get
121 | End Property
122 |
123 | Public ReadOnly Property MaxNorm As Double
124 | Get
125 | MaxNorm = Max(Max(Abs(val(0, 0)), Abs(val(0, 1))), Abs(val(0, 2)))
126 | MaxNorm = Max(MaxNorm, Max(Max(Abs(val(1, 0)), Abs(val(1, 1))), Abs(val(1, 2))))
127 | MaxNorm = Max(MaxNorm, Max(Max(Abs(val(2, 0)), Abs(val(2, 1))), Abs(val(2, 2))))
128 | End Get
129 | End Property
130 |
131 | Public ReadOnly Property IsZero As Boolean
132 | Get
133 | Return Me = New Matrix3d
134 | End Get
135 | End Property
136 |
137 | Public ReadOnly Property IsIdentity As Boolean
138 | Get
139 | Return Me = Matrix3d.Identity
140 | End Get
141 | End Property
142 |
143 | Public ReadOnly Property IsOrthogonal As Boolean
144 | Get
145 | Return Me.Transpose * Me = Matrix3d.Identity
146 | End Get
147 | End Property
148 |
149 | Public Function Add(ByVal a As Double) As Matrix3d
150 | Dim B As Matrix3d = New Matrix3d()
151 | For i As Integer = 0 To 2
152 | For j As Integer = 0 To 2
153 | B.val(i, j) = Me.val(i, j) + a
154 | Next
155 | Next
156 | Return B
157 | End Function
158 | Public Function Add(ByVal a As Matrix3d) As Matrix3d
159 | Dim B As Matrix3d = New Matrix3d()
160 | For i As Integer = 0 To 2
161 | For j As Integer = 0 To 2
162 | B.val(i, j) = Me.val(i, j) + a.val(i, j)
163 | Next
164 | Next
165 | Return B
166 | End Function
167 | Public Function Subtract(ByVal a As Matrix3d) As Matrix3d
168 | Dim B As Matrix3d = New Matrix3d()
169 | For i As Integer = 0 To 2
170 | For j As Integer = 0 To 2
171 | B.val(i, j) = Me.val(i, j) - a.val(i, j)
172 | Next
173 | Next
174 | Return B
175 | End Function
176 |
177 | Public Function Mult(ByVal a As Double) As Matrix3d
178 | Dim B As Matrix3d = New Matrix3d()
179 | For i As Integer = 0 To 2
180 | For j As Integer = 0 To 2
181 | B.val(i, j) = a * Me.val(i, j)
182 | Next
183 | Next
184 | Return B
185 | End Function
186 | Public Function Mult(ByVal a As Vector3d) As Vector3d
187 | Dim b As Vector3d = New Vector3d(0, 0, 0)
188 | b(0) = val(0, 0) * a(0) + val(0, 1) * a(1) + val(0, 2) * a(2)
189 | b(1) = val(1, 0) * a(0) + val(1, 1) * a(1) + val(1, 2) * a(2)
190 | b(2) = val(2, 0) * a(0) + val(2, 1) * a(1) + val(2, 2) * a(2)
191 | Return b
192 | End Function
193 | Public Function Mult(ByVal p As Point3d) As Point3d
194 | Dim b As Point3d = New Point3d(0, 0, 0, p.Coord)
195 | b.X = val(0, 0) * p.X + val(0, 1) * p.Y + val(0, 2) * p.Z
196 | b.Y = val(1, 0) * p.X + val(1, 1) * p.Y + val(1, 2) * p.Z
197 | b.Z = val(2, 0) * p.X + val(2, 1) * p.Y + val(2, 2) * p.Z
198 | Return b
199 | End Function
200 | Public Function Mult(ByVal a As Matrix3d) As Matrix3d
201 | Dim B As Matrix3d = New Matrix3d()
202 | For i As Integer = 0 To 2
203 | For j As Integer = 0 To 2
204 | For k As Integer = 0 To 2
205 | B.val(i, j) = B.val(i, j) + Me.val(i, k) * a.val(k, j)
206 | Next
207 | Next
208 | Next
209 | Return B
210 | End Function
211 |
212 | Public Function Inverse() As Matrix3d
213 | Dim B As Matrix3d = New Matrix3d()
214 |
215 | Dim k11 As Double = val(2, 2) * val(1, 1) - val(2, 1) * val(1, 2)
216 | Dim k12 As Double = val(2, 1) * val(0, 2) - val(2, 2) * val(0, 1)
217 | Dim k13 As Double = val(1, 2) * val(0, 1) - val(1, 1) * val(0, 2)
218 | Dim k21 As Double = val(2, 0) * val(1, 2) - val(2, 2) * val(1, 0)
219 | Dim k22 As Double = val(2, 2) * val(0, 0) - val(2, 0) * val(0, 2)
220 | Dim k23 As Double = val(1, 0) * val(0, 2) - val(1, 2) * val(0, 0)
221 | Dim k31 As Double = val(2, 1) * val(1, 0) - val(2, 0) * val(1, 1)
222 | Dim k32 As Double = val(2, 0) * val(0, 1) - val(2, 1) * val(0, 0)
223 | Dim k33 As Double = val(1, 1) * val(0, 0) - val(1, 0) * val(0, 1)
224 |
225 | Dim det As Double = val(0, 0) * k11 + val(1, 0) * k12 + val(2, 0) * k13
226 |
227 | If det <> 0.0 Then
228 | B.val(0, 0) = k11 / det
229 | B.val(0, 1) = k12 / det
230 | B.val(0, 2) = k13 / det
231 |
232 | B.val(1, 0) = k21 / det
233 | B.val(1, 1) = k22 / det
234 | B.val(1, 2) = k23 / det
235 |
236 | B.val(2, 0) = k31 / det
237 | B.val(2, 1) = k32 / det
238 | B.val(2, 2) = k33 / det
239 | Else
240 | Throw New Exception("Matrix is singular")
241 | End If
242 |
243 | Return B
244 | End Function
245 |
246 | Public Function Transpose() As Matrix3d
247 | Dim T As Matrix3d = Me.Clone
248 | T(0, 1) = Me(1, 0)
249 | T(0, 2) = Me(2, 0)
250 | T(1, 0) = Me(0, 1)
251 | T(1, 2) = Me(2, 1)
252 | T(2, 0) = Me(0, 2)
253 | T(2, 1) = Me(1, 2)
254 | Return T
255 | End Function
256 |
257 | Public Shared Function RotationMatrix(axis As Vector3d, alpha As Double) As Matrix3d
258 | Dim R As Matrix3d = New Matrix3d()
259 | Dim v As Vector3d = axis.Normalized
260 | Dim c As Double = Cos(alpha)
261 | Dim s As Double = Sin(alpha)
262 |
263 | R(0, 0) = c + v.X ^ 2 * (1 - c)
264 | R(0, 1) = v.X * v.Y * (1 - c) - v.Z * s
265 | R(0, 2) = v.X * v.Z * (1 - c) + v.Y * s
266 |
267 | R(1, 0) = v.Y * v.X * (1 - c) + v.Z * s
268 | R(1, 1) = c + v.Y ^ 2 * (1 - c)
269 | R(1, 2) = v.Y * v.Z * (1 - c) - v.X * s
270 |
271 | R(2, 0) = v.Z * v.X * (1 - c) - v.Y * s
272 | R(2, 1) = v.Z * v.Y * (1 - c) + v.X * s
273 | R(2, 2) = c + v.Z ^ 2 * (1 - c)
274 |
275 | Return R
276 | End Function
277 |
278 | Public Overloads Overrides Function Equals(obj As Object) As Boolean
279 | If obj Is Nothing OrElse Not Me.GetType() Is obj.GetType() Then
280 | Return False
281 | End If
282 | Dim m As Matrix3d = CType(obj, Matrix3d)
283 | Return (Me - m).MaxNorm < GeometRi3D.Tolerance
284 | End Function
285 |
286 | Public Overrides Function GetHashCode() As Integer
287 | Return GeometRi3D.HashFunction(Row1.GetHashCode, Row2.GetHashCode, Row3.GetHashCode)
288 | End Function
289 |
290 | Public Overrides Function ToString() As String
291 | Return String.Format("Row1 -> ({0,10:g5}, {1,10:g5}, {2,10:g5})", val(0, 0), val(0, 1), val(0, 2)) +
292 | vbCrLf +
293 | String.Format("Row2 -> ({0,10:g5}, {1,10:g5}, {2,10:g5})", val(1, 0), val(1, 1), val(1, 2)) +
294 | vbCrLf +
295 | String.Format("Row3 -> ({0,10:g5}, {1,10:g5}, {2,10:g5})", val(2, 0), val(2, 1), val(2, 2))
296 | End Function
297 |
298 | ' Operators overloads
299 | '-----------------------------------------------------------------
300 | ' "+"
301 | Public Shared Operator +(m As Matrix3d, a As Matrix3d) As Matrix3d
302 | Return m.Add(a)
303 | End Operator
304 | ' "-"
305 | Public Shared Operator -(m As Matrix3d) As Matrix3d
306 | Return m.Mult(-1.0)
307 | End Operator
308 | Public Shared Operator -(m As Matrix3d, a As Matrix3d) As Matrix3d
309 | Return m.Subtract(a)
310 | End Operator
311 | ' "*"
312 | Public Shared Operator *(m As Matrix3d, a As Double) As Matrix3d
313 | Return m.Mult(a)
314 | End Operator
315 | Public Shared Operator *(a As Double, m As Matrix3d) As Matrix3d
316 | Return m.Mult(a)
317 | End Operator
318 | Public Shared Operator *(m As Matrix3d, a As Vector3d) As Vector3d
319 | Return m.Mult(a)
320 | End Operator
321 | Public Shared Operator *(m As Matrix3d, p As Point3d) As Point3d
322 | Return m.Mult(p)
323 | End Operator
324 | Public Shared Operator *(m As Matrix3d, a As Matrix3d) As Matrix3d
325 | Return m.Mult(a)
326 | End Operator
327 |
328 | Public Shared Operator =(m1 As Matrix3d, m2 As Matrix3d) As Boolean
329 | Return m1.Equals(m2)
330 | End Operator
331 | Public Shared Operator <>(m1 As Matrix3d, m2 As Matrix3d) As Boolean
332 | Return Not m1.Equals(m2)
333 | End Operator
334 |
335 | End Class
336 |
--------------------------------------------------------------------------------
/GeometRi/GeometRi/Plane3D.vb:
--------------------------------------------------------------------------------
1 | Imports System.Math
2 |
3 | Public Class Plane3d
4 |
5 | Implements ICloneable
6 |
7 | Private _point As Point3d
8 | Private _normal As Vector3d
9 | Private _coord As Coord3d
10 |
11 | #Region "Constructors"
12 | '''
13 | ''' Create default XY plane
14 | '''
15 | Public Sub New()
16 | _point = New Point3d(0, 0, 0)
17 | _normal = New Vector3d(0, 0, 1)
18 | End Sub
19 |
20 | '''
21 | ''' Create plane using general equation in 3D space: A*x+B*y+C*z+D=0.
22 | '''
23 | ''' Parameter "A" in general plane equation.
24 | ''' Parameter "B" in general plane equation.
25 | ''' Parameter "C" in general plane equation.
26 | ''' Parameter "D" in general plane equation.
27 | ''' Coordinate system in which plane equation is defined (default: Coord3d.GlobalCS).
28 | Public Sub New(a As Double, b As Double, c As Double, d As Double, Optional coord As Coord3d = Nothing)
29 | If coord Is Nothing Then
30 | coord = Coord3d.GlobalCS
31 | End If
32 | If Abs(a) > Abs(b) AndAlso Abs(a) > Abs(c) Then
33 | _point = New Point3d(-d / a, 0, 0, coord)
34 | ElseIf Abs(b) > Abs(a) AndAlso Abs(b) > Abs(c) Then
35 | _point = New Point3d(0, -d / b, 0, coord)
36 | Else
37 | _point = New Point3d(0, 0, -d / c, coord)
38 | End If
39 | _normal = New Vector3d(a, b, c, coord)
40 | End Sub
41 |
42 | '''
43 | ''' Create plane by three points.
44 | '''
45 | ''' First point.
46 | ''' Second point.
47 | ''' Third point.
48 | Public Sub New(p1 As Point3d, p2 As Point3d, p3 As Point3d)
49 | Dim v1 As Vector3d = New Vector3d(p1, p2)
50 | Dim v2 As Vector3d = New Vector3d(p1, p3)
51 | _normal = v1.Cross(v2)
52 | _point = p1.Clone
53 | End Sub
54 |
55 | '''
56 | ''' Create plane by point and two vectors lying in the plane.
57 | '''
58 | Public Sub New(p1 As Point3d, v1 As Vector3d, v2 As Vector3d)
59 | _normal = v1.Cross(v2)
60 | _point = p1.Clone
61 | End Sub
62 |
63 | '''
64 | ''' Create plane by point and normal vector.
65 | '''
66 | '''
67 | '''
68 | Public Sub New(p1 As Point3d, v1 As Vector3d)
69 | _normal = v1.Clone
70 | _point = p1.Clone
71 | End Sub
72 | #End Region
73 |
74 |
75 | Public Function Clone() As Object Implements ICloneable.Clone
76 | Dim newobj As Plane3d = DirectCast(MemberwiseClone(), Plane3d)
77 | newobj.Point = newobj.Point.Clone
78 | newobj.Normal = newobj.Normal.Clone
79 | Return newobj
80 | End Function
81 |
82 | '''
83 | ''' Point on the plane
84 | '''
85 | '''
86 | Public Property Point As Point3d
87 | Get
88 | Return _point.Clone
89 | End Get
90 | Set(value As Point3d)
91 | _point = value.Clone
92 | End Set
93 | End Property
94 |
95 | '''
96 | ''' Normal vector of the plane
97 | '''
98 | '''
99 | Public Property Normal As Vector3d
100 | Get
101 | Return _normal.Clone
102 | End Get
103 | Set(value As Vector3d)
104 | _normal = value.Clone
105 | End Set
106 | End Property
107 |
108 | '''
109 | ''' Set reference coordinate system for general plane equation
110 | '''
111 | Public Sub SetCoord(coord As Coord3d)
112 | _coord = coord
113 | End Sub
114 |
115 | '''
116 | ''' Coefficient A in the general plane equation
117 | '''
118 | Public ReadOnly Property A As Double
119 | Get
120 | A = _normal.ConvertTo(_coord).X
121 | End Get
122 | End Property
123 |
124 | '''
125 | ''' Coefficient B in the general plane equation
126 | '''
127 | Public ReadOnly Property B As Double
128 | Get
129 | B = _normal.ConvertTo(_coord).Y
130 | End Get
131 | End Property
132 |
133 | '''
134 | ''' Coefficient C in the general plane equation
135 | '''
136 | Public ReadOnly Property C As Double
137 | Get
138 | C = _normal.ConvertTo(_coord).Z
139 | End Get
140 | End Property
141 |
142 | '''
143 | ''' Coefficient D in the general plane equation
144 | '''
145 | Public ReadOnly Property D As Double
146 | Get
147 | Dim p As Point3d = _point.ConvertTo(_coord)
148 | Dim v As Vector3d = _normal.ConvertTo(_coord)
149 | D = -v.X * p.X - v.Y * p.Y - v.Z * p.Z
150 | End Get
151 | End Property
152 |
153 |
154 |
155 | '''
156 | ''' Get intersection of line with plane.
157 | ''' Returns object of type 'Nothing', 'Point3d' or 'Line3d'.
158 | '''
159 | Public Function IntersectionWith(l As Line3d) As Object
160 | Dim r1 As Vector3d = New Vector3d(l.Point)
161 | Dim s1 As Vector3d = l.Direction
162 | Dim n2 As Vector3d = Me.Normal
163 | If Abs(s1 * n2) < GeometRi3D.Tolerance Then
164 | ' Line and plane are parallel
165 | If l.Point.BelongsTo(Me) Then
166 | ' Line lies in the plane
167 | Return l
168 | Else
169 | Return Nothing
170 | End If
171 | Else
172 | r1 = r1 - ((r1 * n2) + Me.D) / (s1 * n2) * s1
173 | Return r1.ToPoint
174 | End If
175 | End Function
176 |
177 | '''
178 | ''' Finds the common intersection of three planes.
179 | ''' Return object of type 'Nothing', 'Point3d', 'Line3d' or 'Plane3d'
180 | '''
181 | Public Function IntersectionWith(s2 As Plane3d, s3 As Plane3d) As Object
182 | ' Set all planes to global CS
183 | Me.SetCoord(Coord3d.GlobalCS)
184 | s2.SetCoord(Coord3d.GlobalCS)
185 | s3.SetCoord(Coord3d.GlobalCS)
186 | Dim det As Double = New Matrix3d({A, B, C}, {s2.A, s2.B, s2.C}, {s3.A, s3.B, s3.C}).Det
187 | If Abs(det) < GeometRi3D.Tolerance Then
188 | If Me.Normal.IsParallelTo(s2.Normal) AndAlso Me.Normal.IsParallelTo(s3.Normal) Then
189 | ' Planes are coplanar
190 | If Me.Point.BelongsTo(s2) AndAlso Me.Point.BelongsTo(s3) Then
191 | Return Me
192 | Else
193 | Return Nothing
194 | End If
195 | End If
196 | If Me.Normal.IsNotParallelTo(s2.Normal) AndAlso Me.Normal.IsNotParallelTo(s3.Normal) Then
197 | ' Planes are not parallel
198 | ' Find the intersection (Me,s2) and (Me,s3) and check if it is the same line
199 | Dim l1 As Line3d = Me.IntersectionWith(s2)
200 | Dim l2 As Line3d = Me.IntersectionWith(s3)
201 | If l1 = l2 Then
202 | Return l1
203 | Else
204 | Return Nothing
205 | End If
206 | End If
207 |
208 | ' Two planes are parallel, third plane is not
209 | Return Nothing
210 |
211 | Else
212 | Dim x As Double = -New Matrix3d({D, B, C}, {s2.D, s2.B, s2.C}, {s3.D, s3.B, s3.C}).Det / det
213 | Dim y As Double = -New Matrix3d({A, D, C}, {s2.A, s2.D, s2.C}, {s3.A, s3.D, s3.C}).Det / det
214 | Dim z As Double = -New Matrix3d({A, B, D}, {s2.A, s2.B, s2.D}, {s3.A, s3.B, s3.D}).Det / det
215 | Return New Point3d(x, y, z)
216 | End If
217 | End Function
218 |
219 | '''
220 | ''' Get intersection of two planes.
221 | ''' Returns object of type 'Nothing', 'Line3d' or 'Plane3d'.
222 | '''
223 | Public Function IntersectionWith(s2 As Plane3d) As Object
224 | Dim v As Vector3d = Me.Normal.Cross(s2.Normal).ConvertToGlobal
225 | If v.Norm < GeometRi3D.Tolerance Then
226 | ' Planes are coplanar
227 | If Me.Point.BelongsTo(s2) Then
228 | Return Me
229 | Else
230 | Return Nothing
231 | End If
232 |
233 | Else
234 | ' Find the common point for two planes by intersecting with third plane
235 | ' (using the 'most orthogonal' plane)
236 | ' This part needs to be rewritten
237 | If Abs(v.X) > Abs(v.Y) AndAlso Abs(v.X) > Abs(v.Z) Then
238 | Dim p As Point3d = Me.IntersectionWith(s2, Coord3d.GlobalCS.YZ_plane)
239 | Return New Line3d(p, v)
240 | ElseIf Abs(v.Y) > Abs(v.X) AndAlso Abs(v.Y) > Abs(v.Z) Then
241 | Dim p As Point3d = Me.IntersectionWith(s2, Coord3d.GlobalCS.XZ_plane)
242 | Return New Line3d(p, v)
243 | Else
244 | Dim p As Point3d = Me.IntersectionWith(s2, Coord3d.GlobalCS.XY_plane)
245 | Return New Line3d(p, v)
246 | End If
247 | End If
248 | End Function
249 |
250 | '''
251 | ''' Get intersection of plane with sphere.
252 | ''' Returns object of type 'Nothing', 'Point3d' or 'Circle3d'.
253 | '''
254 | Public Function IntersectionWith(s As Sphere)
255 | Return s.IntersectionWith(Me)
256 | End Function
257 |
258 | '''
259 | ''' Intersection of circle with plane.
260 | ''' Returns object of type 'Nothing', 'Circle3d', 'Point3d' or 'Segment3d'.
261 | '''
262 | Public Function IntersectionWith(c As Circle3d)
263 | Return c.IntersectionWith(Me)
264 | End Function
265 |
266 |
267 | #Region "AngleTo"
268 | '''
269 | ''' Angle between vector and plane in radians (0 < angle < Pi/2)
270 | '''
271 | Public Function AngleTo(v As Vector3d) As Double
272 | Return Abs(PI / 2 - Me.Normal.AngleTo(v))
273 | End Function
274 | '''
275 | ''' Angle between vector and plane in degrees (0 < angle < 90)
276 | '''
277 | Public Function AngleToDeg(v As Vector3d) As Double
278 | Return Abs(90.0 - Me.Normal.AngleToDeg(v))
279 | End Function
280 |
281 | '''
282 | ''' Angle between line and plane in radians (0 < angle < Pi/2)
283 | '''
284 | Public Function AngleTo(l As Line3d) As Double
285 | Return Abs(PI / 2 - Me.Normal.AngleTo(l.Direction))
286 | End Function
287 | '''
288 | ''' Angle between line and plane in degrees (0 < angle < 90)
289 | '''
290 | Public Function AngleToDeg(l As Line3d) As Double
291 | Return Abs(90.0 - Me.Normal.AngleToDeg(l.Direction))
292 | End Function
293 |
294 | '''
295 | ''' Angle between two planes in radians (0 < angle < Pi/2)
296 | '''
297 | Public Function AngleTo(s As Plane3d) As Double
298 | Dim ang As Double = Me.Normal.AngleTo(s.Normal)
299 | If ang <= PI / 2 Then
300 | Return ang
301 | Else
302 | Return PI - ang
303 | End If
304 | End Function
305 | '''
306 | ''' Angle between two planes in degrees (0 < angle < 90)
307 | '''
308 | Public Function AngleToDeg(s As Plane3d) As Double
309 | Return AngleTo(s) * 180 / PI
310 | End Function
311 | #End Region
312 |
313 |
314 | #Region "TranslateRotateReflect"
315 | '''
316 | ''' Translate plane by a vector
317 | '''
318 | Public Function Translate(v As Vector3d) As Plane3d
319 | Return New Plane3d(Me.Point.Translate(v), Me.Normal)
320 | End Function
321 |
322 | '''
323 | ''' Rotate plane by a given rotation matrix
324 | '''
325 | Public Function Rotate(ByVal m As Matrix3d) As Plane3d
326 | Return New Plane3d(Me.Point.Rotate(m), Me.Normal.Rotate(m))
327 | End Function
328 |
329 | '''
330 | ''' Rotate plane by a given rotation matrix around point 'p' as a rotation center
331 | '''
332 | Public Function Rotate(m As Matrix3d, p As Point3d) As Plane3d
333 | Return New Plane3d(Me.Point.Rotate(m, p), Me.Normal.Rotate(m))
334 | End Function
335 |
336 | '''
337 | ''' Reflect plane in given point
338 | '''
339 | Public Function ReflectIn(p As Point3d) As Plane3d
340 | Return New Plane3d(Me.Point.ReflectIn(p), Me.Normal.ReflectIn(p))
341 | End Function
342 |
343 | '''
344 | ''' Reflect plane in given line
345 | '''
346 | Public Function ReflectIn(l As Line3d) As Plane3d
347 | Return New Plane3d(Me.Point.ReflectIn(l), Me.Normal.ReflectIn(l))
348 | End Function
349 |
350 | '''
351 | ''' Reflect plane in given plane
352 | '''
353 | Public Function ReflectIn(s As Plane3d) As Plane3d
354 | Return New Plane3d(Me.Point.ReflectIn(s), Me.Normal.ReflectIn(s))
355 | End Function
356 | #End Region
357 |
358 | Public Overloads Overrides Function Equals(obj As Object) As Boolean
359 | If obj Is Nothing OrElse Not Me.GetType() Is obj.GetType() Then
360 | Return False
361 | End If
362 | Dim s As Plane3d = CType(obj, Plane3d)
363 |
364 | Return s.Point.BelongsTo(Me) AndAlso s.Normal.IsParallelTo(Me.Normal)
365 | End Function
366 |
367 | Public Overrides Function GetHashCode() As Integer
368 | Return GeometRi3D.HashFunction(_point.GetHashCode, _normal.GetHashCode)
369 | End Function
370 |
371 | Public Overloads Function ToString(Optional coord As Coord3d = Nothing) As String
372 | Dim str As New System.Text.StringBuilder
373 | Dim P As Point3d = _point.ConvertToGlobal
374 | Dim normal As Vector3d = _normal.ConvertToGlobal
375 | If coord IsNot Nothing Then
376 | P = _point.ConvertTo(coord)
377 | normal = _normal.ConvertTo(coord)
378 | End If
379 | str.Append("Plane3d:" + vbCrLf)
380 | str.Append(String.Format("Point -> ({0,10:g5}, {1,10:g5}, {2,10:g5})", P.X, P.Y, P.Z) + vbCrLf)
381 | str.Append(String.Format("Normal -> ({0,10:g5}, {1,10:g5}, {2,10:g5})", normal.X, normal.Y, normal.Z))
382 | Return str.ToString
383 | End Function
384 |
385 | ' Operators overloads
386 | '-----------------------------------------------------------------
387 |
388 | Public Shared Operator =(s1 As Plane3d, s2 As Plane3d) As Boolean
389 | Return s1.Equals(s2)
390 | End Operator
391 | Public Shared Operator <>(s1 As Plane3d, s2 As Plane3d) As Boolean
392 | Return Not s1.Equals(s2)
393 | End Operator
394 |
395 | End Class
396 |
--------------------------------------------------------------------------------
/GeometRi/GeometRi/Ray3D.vb:
--------------------------------------------------------------------------------
1 | Imports System.Math
2 |
3 | Public Class Ray3d
4 |
5 | Implements ICloneable
6 |
7 | Protected _point As Point3d
8 | Protected _dir As Vector3d
9 |
10 | Public Sub New()
11 | _point = New Point3d()
12 | _dir = New Vector3d(1, 0, 0)
13 | End Sub
14 | Public Sub New(ByVal p As Point3d, ByVal v As Vector3d)
15 | _point = p.Clone
16 | _dir = v.ConvertTo(p.Coord).Normalized
17 | End Sub
18 |
19 | Public Function Clone() As Object Implements ICloneable.Clone
20 | Dim newobj As Line3d = DirectCast(MemberwiseClone(), Line3d)
21 | newobj.Point = newobj.Point.Clone
22 | newobj.Direction = newobj.Direction.Clone
23 | Return newobj
24 | End Function
25 |
26 | '''
27 | ''' Base point of the ray
28 | '''
29 | '''
30 | Public Property Point As Point3d
31 | Get
32 | Return _point.Clone
33 | End Get
34 | Set(value As Point3d)
35 | _point = value.Clone
36 | End Set
37 | End Property
38 |
39 | '''
40 | ''' Direction vector of the ray
41 | '''
42 | '''
43 | Public Property Direction As Vector3d
44 | Get
45 | Return _dir.Clone
46 | End Get
47 | Set(value As Vector3d)
48 | _dir = value.Clone
49 | End Set
50 | End Property
51 |
52 | '''
53 | ''' Convert ray to line
54 | '''
55 | Public ReadOnly Property ToLine As Line3d
56 | Get
57 | Return New Line3d(Me.Point, Me.Direction)
58 | End Get
59 | End Property
60 |
61 | #Region "DistanceTo"
62 | '''
63 | ''' Distance from ray to point
64 | '''
65 | Public Function DistanceTo(p As Point3d) As Double
66 | Return p.DistanceTo(Me)
67 | End Function
68 |
69 | '''
70 | ''' Shortest distance to a line
71 | '''
72 | Public Function DistanceTo(l As Line3d) As Double
73 | Dim r1 As Vector3d = Me.Point.ToVector
74 | Dim r2 As Vector3d = l.Point.ToVector
75 | Dim s1 As Vector3d = Me.Direction
76 | Dim s2 As Vector3d = l.Direction
77 | If s1.Cross(s2).Norm > GeometRi3D.Tolerance Then
78 | ' Crossing lines
79 | Dim p As Point3d = l.PerpendicularTo(New Line3d(Me.Point, Me.Direction))
80 | If p.BelongsTo(Me) Then
81 | Return Abs((r2 - r1) * s1.Cross(s2)) / s1.Cross(s2).Norm
82 | Else
83 | Return Me.Point.DistanceTo(l)
84 | End If
85 | Else
86 | ' Parallel lines
87 | Return (r2 - r1).Cross(s1).Norm / s1.Norm
88 | End If
89 | End Function
90 |
91 | '''
92 | ''' Distance to a segment
93 | '''
94 | Public Function DistanceTo(s As Segment3d) As Double
95 | Return s.DistanceTo(Me)
96 | End Function
97 |
98 | '''
99 | ''' Distance between two rays
100 | '''
101 | Public Function DistanceTo(r As Ray3d) As Double
102 |
103 | If Me.Direction.IsParallelTo(r.Direction) Then Return Me.ToLine.DistanceTo(r.ToLine)
104 |
105 | If Me.ToLine.PerpendicularTo(r.ToLine).BelongsTo(r) AndAlso
106 | r.ToLine.PerpendicularTo(Me.ToLine).BelongsTo(Me) Then
107 | Return Me.ToLine.DistanceTo(r.ToLine)
108 | End If
109 |
110 | Dim d1 As Double = Double.PositiveInfinity
111 | Dim d2 As Double = Double.PositiveInfinity
112 | Dim flag As Boolean = False
113 |
114 | If r.Point.ProjectionTo(Me.ToLine).BelongsTo(Me) Then
115 | d1 = r.Point.DistanceTo(Me.ToLine)
116 | flag = True
117 | End If
118 | If Me.Point.ProjectionTo(r.ToLine).BelongsTo(r) Then
119 | d2 = Me.Point.DistanceTo(r.ToLine)
120 | flag = True
121 | End If
122 |
123 | If flag Then
124 | Return Min(d1, d2)
125 | Else
126 | Return Me.Point.DistanceTo(r.Point)
127 | End If
128 |
129 | End Function
130 | #End Region
131 |
132 |
133 | '''
134 | ''' Point on the perpendicular to the line
135 | '''
136 | Public Function PerpendicularTo(l As Line3d) As Point3d
137 | Dim r1 As Vector3d = Me.Point.ToVector
138 | Dim r2 As Vector3d = l.Point.ToVector
139 | Dim s1 As Vector3d = Me.Direction
140 | Dim s2 As Vector3d = l.Direction
141 | If s1.Cross(s2).Norm > GeometRi3D.Tolerance Then
142 | Dim p As Point3d = l.PerpendicularTo(New Line3d(Me.Point, Me.Direction))
143 | If p.BelongsTo(Me) Then
144 | r1 = r2 + (r2 - r1) * s1.Cross(s1.Cross(s2)) / (s1 * s2.Cross(s1.Cross(s2))) * s2
145 | Return r1.ToPoint
146 | Else
147 | Return Me.Point.ProjectionTo(l)
148 | End If
149 | Else
150 | Throw New Exception("Lines are parallel")
151 | End If
152 | End Function
153 |
154 | '''
155 | ''' Get intersection of ray with plane.
156 | ''' Returns object of type 'Nothing', 'Point3d' or 'Ray3d'.
157 | '''
158 | Public Function IntersectionWith(s As Plane3d) As Object
159 |
160 | Dim r1 As Vector3d = Me.Point.ToVector
161 | Dim s1 As Vector3d = Me.Direction
162 | Dim n2 As Vector3d = s.Normal
163 | If Abs(s1 * n2) < GeometRi3D.Tolerance Then
164 | ' Ray and plane are parallel
165 | If Me.Point.BelongsTo(s) Then
166 | ' Ray lies in the plane
167 | Return Me
168 | Else
169 | Return Nothing
170 | End If
171 | Else
172 | ' Intersection point
173 | s.SetCoord(r1.Coord)
174 | r1 = r1 - ((r1 * n2) + s.D) / (s1 * n2) * s1
175 | If r1.ToPoint.BelongsTo(Me) Then
176 | Return r1.ToPoint
177 | Else
178 | Return Nothing
179 | End If
180 | End If
181 | End Function
182 |
183 | '''
184 | ''' Get the orthogonal projection of a ray to the plane.
185 | ''' Return object of type 'Ray3d' or 'Point3d'
186 | '''
187 | Public Function ProjectionTo(s As Plane3d) As Object
188 | Dim n1 As Vector3d = s.Normal
189 | Dim n2 As Vector3d = Me.Direction.Cross(n1)
190 | If n2.Norm < GeometRi3D.Tolerance Then
191 | ' Ray is perpendicular to the plane
192 | Return Me.Point.ProjectionTo(s)
193 | Else
194 | Return New Ray3d(Me.Point.ProjectionTo(s), n1.Cross(n2))
195 | End If
196 | End Function
197 |
198 | '''
199 | ''' Angle between ray and plane in radians (0 < angle < Pi/2)
200 | '''
201 | Public Function AngleTo(s As Plane3d) As Double
202 | Dim ang As Double = Asin(Me.Direction.Dot(s.Normal) / Me.Direction.Norm / s.Normal.Norm)
203 | Return Abs(ang)
204 | End Function
205 | '''
206 | ''' Angle between ray and plane in degrees (0 < angle < 90)
207 | '''
208 | Public Function AngleToDeg(s As Plane3d) As Double
209 | Return AngleTo(s) * 180 / PI
210 | End Function
211 |
212 | #Region "TranslateRotateReflect"
213 | '''
214 | ''' Translate ray by a vector
215 | '''
216 | Public Function Translate(v As Vector3d) As Ray3d
217 | Dim l As Ray3d = Me.Clone
218 | l.Point = l.Point.Translate(v)
219 | Return l
220 | End Function
221 |
222 | '''
223 | ''' Rotate ray by a given rotation matrix
224 | '''
225 | Public Function Rotate(ByVal m As Matrix3d) As Ray3d
226 | Dim l As Ray3d = Me.Clone
227 | l.Point = l.Point.Rotate(m)
228 | l.Direction = l.Direction.Rotate(m)
229 | Return l
230 | End Function
231 |
232 | '''
233 | ''' Rotate ray by a given rotation matrix around point 'p' as a rotation center
234 | '''
235 | Public Function Rotate(m As Matrix3d, p As Point3d) As Ray3d
236 | Dim l As Ray3d = Me.Clone
237 | l.Point = l.Point.Rotate(m, p)
238 | l.Direction = l.Direction.Rotate(m)
239 | Return l
240 | End Function
241 |
242 | '''
243 | ''' Reflect ray in given point
244 | '''
245 | Public Function ReflectIn(p As Point3d) As Ray3d
246 | Return New Ray3d(Me.Point.ReflectIn(p), Me.Direction.ReflectIn(p))
247 | End Function
248 |
249 | '''
250 | ''' Reflect ray in given line
251 | '''
252 | Public Function ReflectIn(l As Line3d) As Ray3d
253 | Return New Ray3d(Me.Point.ReflectIn(l), Me.Direction.ReflectIn(l))
254 | End Function
255 |
256 | '''
257 | ''' Reflect ray in given plane
258 | '''
259 | Public Function ReflectIn(s As Plane3d) As Ray3d
260 | Return New Ray3d(Me.Point.ReflectIn(s), Me.Direction.ReflectIn(s))
261 | End Function
262 | #End Region
263 |
264 | Public Overloads Overrides Function Equals(obj As Object) As Boolean
265 | If obj Is Nothing OrElse Not Me.GetType() Is obj.GetType() Then
266 | Return False
267 | End If
268 | Dim r As Ray3d = CType(obj, Ray3d)
269 | Return Me.Point = r.Point AndAlso Abs(Me.Direction.Normalized * r.Direction.Normalized - 1) < GeometRi3D.Tolerance
270 | End Function
271 |
272 | Public Overrides Function GetHashCode() As Integer
273 | Return GeometRi3D.HashFunction(_point.GetHashCode, _dir.GetHashCode)
274 | End Function
275 |
276 | Public Overloads Function ToString(Optional coord As Coord3d = Nothing) As String
277 | Dim str As New System.Text.StringBuilder
278 | Dim P As Point3d = _point.ConvertToGlobal
279 | Dim dir As Vector3d = _dir.ConvertToGlobal
280 | If coord IsNot Nothing Then
281 | P = _point.ConvertTo(coord)
282 | dir = _dir.ConvertTo(coord)
283 | End If
284 | str.Append("Ray:" + vbCrLf)
285 | str.Append(String.Format("Point -> ({0,10:g5}, {1,10:g5}, {2,10:g5})", P.X, P.Y, P.Z) + vbCrLf)
286 | str.Append(String.Format("Direction -> ({0,10:g5}, {1,10:g5}, {2,10:g5})", dir.X, dir.Y, dir.Z))
287 | Return str.ToString
288 | End Function
289 |
290 | ' Operators overloads
291 | '-----------------------------------------------------------------
292 | Public Overloads Shared Operator =(l1 As Ray3d, l2 As Ray3d) As Boolean
293 | Return l1.Equals(l2)
294 | End Operator
295 | Public Overloads Shared Operator <>(l1 As Ray3d, l2 As Ray3d) As Boolean
296 | Return Not l1.Equals(l2)
297 | End Operator
298 |
299 |
300 | End Class
301 |
--------------------------------------------------------------------------------
/GeometRi/GeometRi/Segment3D.vb:
--------------------------------------------------------------------------------
1 | Imports System.Math
2 |
3 | Public Class Segment3d
4 |
5 | Implements ICloneable
6 |
7 | Private _p1 As Point3d
8 | Private _p2 As Point3d
9 |
10 | Sub New(p1 As Point3d, p2 As Point3d)
11 | _p1 = p1.Clone
12 | _p2 = p2.ConvertTo(p1.Coord)
13 | End Sub
14 |
15 | Public Function Clone() As Object Implements ICloneable.Clone
16 | Dim newobj As Segment3d = DirectCast(MemberwiseClone(), Segment3d)
17 | newobj.P1 = newobj.P1.Clone
18 | newobj.P2 = newobj.P2.Clone
19 | Return newobj
20 | End Function
21 |
22 | Public Property P1 As Point3d
23 | Get
24 | Return _p1.Clone
25 | End Get
26 | Set(value As Point3d)
27 | _p1 = value.Clone
28 | End Set
29 | End Property
30 |
31 | Public Property P2 As Point3d
32 | Get
33 | Return _p2.Clone
34 | End Get
35 | Set(value As Point3d)
36 | _p2 = value.Clone
37 | End Set
38 | End Property
39 |
40 | Public ReadOnly Property Length As Double
41 | Get
42 | Return _p1.DistanceTo(_p2)
43 | End Get
44 | End Property
45 |
46 | Public ReadOnly Property ToVector As Vector3d
47 | Get
48 | Return New Vector3d(_p1, _p2)
49 | End Get
50 | End Property
51 |
52 | Public ReadOnly Property ToRay As Ray3d
53 | Get
54 | Return New Ray3d(_p1, New Vector3d(_p1, _p2))
55 | End Get
56 | End Property
57 |
58 | Public ReadOnly Property ToLine As Line3d
59 | Get
60 | Return New Line3d(_p1, _p2)
61 | End Get
62 | End Property
63 |
64 | #Region "DistanceTo"
65 | '''
66 | ''' Returns shortest distance from segment to the point
67 | '''
68 | Public Function DistanceTo(p As Point3d) As Double
69 | Return p.DistanceTo(Me)
70 | End Function
71 |
72 | '''
73 | ''' Returns shortest distance from segment to the plane
74 | '''
75 | Public Function DistanceTo(s As Plane3d) As Double
76 |
77 | Dim obj As Object = Me.IntersectionWith(s)
78 |
79 | If obj Is Nothing Then
80 | Return Min(Me.P1.DistanceTo(s), Me.P2.DistanceTo(s))
81 | Else
82 | Return 0
83 | End If
84 | End Function
85 |
86 | '''
87 | ''' Returns shortest distance from segment to the line
88 | '''
89 | Public Function DistanceTo(l As Line3d) As Double
90 | If l.PerpendicularTo(Me.ToLine).BelongsTo(Me) Then
91 | Return l.DistanceTo(Me.ToLine)
92 | Else
93 | Return Min(Me.P1.DistanceTo(l), Me.P2.DistanceTo(l))
94 | End If
95 | End Function
96 |
97 | '''
98 | ''' Returns shortest distance between two segments
99 | '''
100 | Public Function DistanceTo(s As Segment3d) As Double
101 |
102 | ' Algorithm by Dan Sunday
103 | ' http://geomalgorithms.com/a07-_distance.html
104 |
105 | Dim small As Double = 0.000000001
106 |
107 | Dim u As Vector3d = Me.ToVector
108 | Dim v As Vector3d = s.ToVector
109 | Dim w As Vector3d = New Vector3d(s.P1, Me.P1)
110 |
111 | Dim a As Double = u * u
112 | Dim b As Double = u * v
113 | Dim c As Double = v * v
114 | Dim d As Double = u * w
115 | Dim e As Double = v * w
116 |
117 | Dim DD As Double = a * c - b * b
118 | Dim sc, sN, sD, tc, tN, tD As Double
119 | sD = DD
120 | tD = DD
121 |
122 | If DD < small Then
123 | ' the lines are almost parallel, force using point Me.P1 to prevent possible division by 0.0 later
124 | sN = 0.0
125 | sD = 1.0
126 | tN = e
127 | tD = c
128 | Else
129 | ' get the closest points on the infinite lines
130 | sN = (b * e - c * d)
131 | tN = (a * e - b * d)
132 | If (sN < 0.0) Then
133 | ' sc < 0 => the s=0 edge Is visible
134 | sN = 0.0
135 | tN = e
136 | tD = c
137 | ElseIf (sN > sD) Then
138 | ' sc > 1 => the s=1 edge Is visible
139 | sN = sD
140 | tN = e + b
141 | tD = c
142 | End If
143 | End If
144 |
145 | If (tN < 0.0) Then
146 | ' tc < 0 => the t=0 edge Is visible
147 | tN = 0.0
148 | ' recompute sc for this edge
149 | If (-d < 0.0) Then
150 | sN = 0.0
151 | ElseIf (-d > a) Then
152 | sN = sD
153 | Else
154 | sN = -d
155 | sD = a
156 | End If
157 | ElseIf (tN > tD) Then
158 | ' tc > 1 => the t=1 edge Is visible
159 | tN = tD
160 | ' recompute sc for this edge
161 | If ((-d + b) < 0.0) Then
162 | sN = 0
163 | ElseIf ((-d + b) > a) Then
164 | sN = sD
165 | Else
166 | sN = (-d + b)
167 | sD = a
168 | End If
169 | End If
170 |
171 | ' finally do the division to get sc And tc
172 | sc = If(Abs(sN) < small, 0.0, sN / sD)
173 | tc = If(Abs(tN) < small, 0.0, tN / tD)
174 |
175 | ' get the difference of the two closest points
176 | Dim dP As Vector3d = w + (sc * u) - (tc * v) ' = S1(sc) - S2(tc)
177 |
178 | Return dP.Norm
179 |
180 | End Function
181 |
182 | '''
183 | ''' Returns shortest distance from segment to ray
184 | '''
185 | Public Function DistanceTo(r As Ray3d) As Double
186 |
187 | If Me.ToVector.IsParallelTo(r.Direction) Then Return Me.ToLine.DistanceTo(r.ToLine)
188 |
189 | If Me.ToLine.PerpendicularTo(r.ToLine).BelongsTo(r) AndAlso
190 | r.ToLine.PerpendicularTo(Me.ToLine).BelongsTo(Me) Then
191 | Return Me.ToLine.DistanceTo(r.ToLine)
192 | End If
193 |
194 | Dim d1 As Double = Double.PositiveInfinity
195 | Dim d2 As Double = Double.PositiveInfinity
196 | Dim d3 As Double = Double.PositiveInfinity
197 | Dim flag As Boolean = False
198 |
199 | If r.Point.ProjectionTo(Me.ToLine).BelongsTo(Me) Then
200 | d1 = r.Point.DistanceTo(Me.ToLine)
201 | flag = True
202 | End If
203 | If Me.P1.ProjectionTo(r.ToLine).BelongsTo(r) Then
204 | d2 = Me.P1.DistanceTo(r.ToLine)
205 | flag = True
206 | End If
207 | If Me.P2.ProjectionTo(r.ToLine).BelongsTo(r) Then
208 | d3 = Me.P2.DistanceTo(r.ToLine)
209 | flag = True
210 | End If
211 |
212 | If flag Then Return Min(d1, Min(d2, d3))
213 |
214 | Return Min(Me.P1.DistanceTo(r.Point), Me.P2.DistanceTo(r.Point))
215 |
216 | End Function
217 | #End Region
218 |
219 | '''
220 | ''' Get intersection of segment with plane.
221 | ''' Returns object of type 'Nothing', 'Point3d' or 'Segment3d'.
222 | '''
223 | Public Function IntersectionWith(s As Plane3d) As Object
224 |
225 | Dim obj As Object = Me.ToRay.IntersectionWith(s)
226 |
227 | If obj Is Nothing Then
228 | Return Nothing
229 | Else
230 | If obj.GetType Is GetType(Ray3d) Then
231 | Return Me
232 | Else
233 | Dim r As New Ray3d(Me.P2, New Vector3d(Me.P2, Me.P1))
234 | Dim obj2 As Object = r.IntersectionWith(s)
235 | If obj2 Is Nothing Then
236 | Return Nothing
237 | Else
238 | Return CType(obj2, Point3d)
239 | End If
240 | End If
241 | End If
242 | End Function
243 |
244 | '''
245 | ''' Get the orthogonal projection of a segment to the line.
246 | ''' Return object of type 'Segment3d' or 'Point3d'
247 | '''
248 | Public Function ProjectionTo(l As Line3d) As Object
249 | If Me.ToVector.IsOrthogonalTo(l.Direction) Then
250 | ' Segment is perpendicular to the line
251 | Return Me.P1.ProjectionTo(l)
252 | Else
253 | Return New Segment3d(Me.P1.ProjectionTo(l), Me.P2.ProjectionTo(l))
254 | End If
255 | End Function
256 |
257 | '''
258 | ''' Get the orthogonal projection of a segment to the plane.
259 | ''' Return object of type 'Segment3d' or 'Point3d'
260 | '''
261 | Public Function ProjectionTo(s As Plane3d) As Object
262 | If Me.ToVector.IsParallelTo(s.Normal) Then
263 | ' Segment is perpendicular to the plane
264 | Return Me.P1.ProjectionTo(s)
265 | Else
266 | Return New Segment3d(Me.P1.ProjectionTo(s), Me.P2.ProjectionTo(s))
267 | End If
268 | End Function
269 |
270 | #Region "AngleTo"
271 | '''
272 | ''' Angle between segment and plane in radians (0 < angle < Pi/2)
273 | '''
274 | Public Function AngleTo(s As Plane3d) As Double
275 | Dim ang As Double = Asin(Me.ToVector.Dot(s.Normal) / Me.ToVector.Norm / s.Normal.Norm)
276 | Return Abs(ang)
277 | End Function
278 | '''
279 | ''' Angle between segment and plane in degrees (0 < angle < 90)
280 | '''
281 | Public Function AngleToDeg(s As Plane3d) As Double
282 | Return AngleTo(s) * 180 / PI
283 | End Function
284 | #End Region
285 |
286 |
287 | #Region "TranslateRotateReflect"
288 | '''
289 | ''' Translate segment by a vector
290 | '''
291 | Public Function Translate(v As Vector3d) As Segment3d
292 | Return New Segment3d(P1.Translate(v), P2.Translate(v))
293 | End Function
294 |
295 | '''
296 | ''' Rotate segment by a given rotation matrix
297 | '''
298 | Public Overridable Function Rotate(ByVal m As Matrix3d) As Segment3d
299 | Return New Segment3d(P1.Rotate(m), P2.Rotate(m))
300 | End Function
301 |
302 | '''
303 | ''' Rotate segment by a given rotation matrix around point 'p' as a rotation center
304 | '''
305 | Public Overridable Function Rotate(m As Matrix3d, p As Point3d) As Segment3d
306 | Return New Segment3d(P1.Rotate(m, p), P2.Rotate(m, p))
307 | End Function
308 |
309 | '''
310 | ''' Reflect segment in given point
311 | '''
312 | Public Overridable Function ReflectIn(p As Point3d) As Segment3d
313 | Return New Segment3d(P1.ReflectIn(p), P2.ReflectIn(p))
314 | End Function
315 |
316 | '''
317 | ''' Reflect segment in given line
318 | '''
319 | Public Overridable Function ReflectIn(l As Line3d) As Segment3d
320 | Return New Segment3d(P1.ReflectIn(l), P2.ReflectIn(l))
321 | End Function
322 |
323 | '''
324 | ''' Reflect segment in given plane
325 | '''
326 | Public Overridable Function ReflectIn(s As Plane3d) As Segment3d
327 | Return New Segment3d(P1.ReflectIn(s), P2.ReflectIn(s))
328 | End Function
329 | #End Region
330 |
331 | Public Overloads Overrides Function Equals(obj As Object) As Boolean
332 | If obj Is Nothing OrElse Not Me.GetType() Is obj.GetType() Then
333 | Return False
334 | End If
335 | Dim s As Segment3d = CType(obj, Segment3d)
336 | Return (Me.P1 = s.P1 AndAlso Me.P2 = s.P2) Or (Me.P1 = s.P2 AndAlso Me.P2 = s.P1)
337 | End Function
338 |
339 | Public Overrides Function GetHashCode() As Integer
340 | Return GeometRi3D.HashFunction(_p1.GetHashCode, _p2.GetHashCode)
341 | End Function
342 |
343 | Public Overloads Function ToString(Optional coord As Coord3d = Nothing) As String
344 | Dim str As New System.Text.StringBuilder
345 | Dim p1 As Point3d = _p1.ConvertToGlobal
346 | Dim p2 As Point3d = _p2.ConvertToGlobal
347 | If coord IsNot Nothing Then
348 | p1 = _p1.ConvertTo(coord)
349 | p2 = _p2.ConvertTo(coord)
350 | End If
351 | str.Append("Segment:" + vbCrLf)
352 | str.Append(String.Format("Point 1 -> ({0,10:g5}, {1,10:g5}, {2,10:g5})", p1.X, p1.Y, p1.Z) + vbCrLf)
353 | str.Append(String.Format("Point 2 -> ({0,10:g5}, {1,10:g5}, {2,10:g5})", p2.X, p2.Y, p2.Z))
354 | Return str.ToString
355 | End Function
356 |
357 | ' Operators overloads
358 | '-----------------------------------------------------------------
359 | Public Overloads Shared Operator =(l1 As Segment3d, l2 As Segment3d) As Boolean
360 | Return l1.Equals(l2)
361 | End Operator
362 | Public Overloads Shared Operator <>(l1 As Segment3d, l2 As Segment3d) As Boolean
363 | Return Not l1.Equals(l2)
364 | End Operator
365 |
366 | End Class
367 |
--------------------------------------------------------------------------------
/GeometRi/GeometRi/Sphere.vb:
--------------------------------------------------------------------------------
1 | Imports System.Math
2 |
3 | Public Class Sphere
4 |
5 | Implements ICloneable
6 |
7 | Private _point As Point3d
8 | Private _r As Double
9 |
10 | Public Sub New(P As Point3d, R As Double)
11 | _point = P.Clone
12 | _r = R
13 | End Sub
14 |
15 |
16 |
17 | Public Function Clone() As Object Implements ICloneable.Clone
18 | Dim newobj As Sphere = DirectCast(MemberwiseClone(), Sphere)
19 | newobj.Center = newobj.Center.Clone
20 | Return newobj
21 | End Function
22 |
23 | #Region "Properties"
24 | '''
25 | ''' Center of the sphere
26 | '''
27 | Public Property Center As Point3d
28 | Get
29 | Return _point.Clone
30 | End Get
31 | Set(value As Point3d)
32 | _point = value.Clone
33 | End Set
34 | End Property
35 |
36 | '''
37 | ''' X component of the spheres' center
38 | '''
39 | Private Property X As Double
40 | Get
41 | Return _point.X
42 | End Get
43 | Set(value As Double)
44 | _point.X = value
45 | End Set
46 | End Property
47 |
48 | '''
49 | ''' Y component of the spheres' center
50 | '''
51 | Private Property Y As Double
52 | Get
53 | Return _point.Y
54 | End Get
55 | Set(value As Double)
56 | _point.Y = value
57 | End Set
58 | End Property
59 |
60 | '''
61 | ''' Z component of the spheres' center
62 | '''
63 | Private Property Z As Double
64 | Get
65 | Return _point.Z
66 | End Get
67 | Set(value As Double)
68 | _point.Z = value
69 | End Set
70 | End Property
71 |
72 | '''
73 | ''' Radius of the sphere
74 | '''
75 | Public Property R As Double
76 | Get
77 | Return _r
78 | End Get
79 | Set(value As Double)
80 | _r = value
81 | End Set
82 | End Property
83 |
84 | Public ReadOnly Property Area As Double
85 | Get
86 | Return 4.0 * PI * _r ^ 2
87 | End Get
88 | End Property
89 |
90 | Public ReadOnly Property Volume As Double
91 | Get
92 | Return 4.0 / 3.0 * PI * _r ^ 3
93 | End Get
94 | End Property
95 | #End Region
96 |
97 | #Region "DistanceTo"
98 | Public Function DistanceTo(p As Point3d) As Double
99 | Dim d As Double = p.DistanceTo(Me.Center)
100 | If d > Me.R Then
101 | Return d - Me.R
102 | Else
103 | Return 0
104 | End If
105 | End Function
106 |
107 | Public Function DistanceTo(l As Line3d) As Double
108 | Dim d As Double = l.DistanceTo(Me.Center)
109 | If d > Me.R Then
110 | Return d - Me.R
111 | Else
112 | Return 0
113 | End If
114 | End Function
115 |
116 | Public Function DistanceTo(r As Ray3d) As Double
117 | If Me.Center.ProjectionTo(r.ToLine).BelongsTo(r) Then
118 | Return Me.DistanceTo(r.ToLine)
119 | Else
120 | Return Me.DistanceTo(r.Point)
121 | End If
122 | End Function
123 |
124 | Public Function DistanceTo(s As Segment3d) As Double
125 | If Me.Center.ProjectionTo(s.ToLine).BelongsTo(s) Then
126 | Return Me.DistanceTo(s.ToLine)
127 | Else
128 | Return Min(Me.DistanceTo(s.P1), Me.DistanceTo(s.P2))
129 | End If
130 | End Function
131 |
132 | Public Function DistanceTo(s As Plane3d) As Double
133 | Dim d As Double = Me.Center.DistanceTo(s)
134 | If d > Me.R Then
135 | Return d - Me.R
136 | Else
137 | Return 0
138 | End If
139 | End Function
140 | #End Region
141 |
142 | #Region "Intersections"
143 | '''
144 | ''' Get intersection of line with sphere.
145 | ''' Returns object of type 'Nothing', 'Point3d' or 'Segment3d'.
146 | '''
147 | Public Function IntersectionWith(l As Line3d) As Object
148 |
149 | Dim d As Double = l.Direction.Normalized * (l.Point.ToVector - Me.Center.ToVector)
150 | Dim det As Double = d ^ 2 - ((l.Point.ToVector - Me.Center.ToVector).Norm) ^ 2 + _r ^ 2
151 |
152 | If det < -GeometRi3D.Tolerance Then
153 | Return Nothing
154 | ElseIf det < GeometRi3D.Tolerance Then
155 | Return l.Point - d * l.Direction.Normalized.ToPoint
156 | Else
157 | Dim p1 As Point3d = l.Point + (-d + Sqrt(det)) * l.Direction.Normalized.ToPoint
158 | Dim p2 As Point3d = l.Point + (-d - Sqrt(det)) * l.Direction.Normalized.ToPoint
159 | Return New Segment3d(p1, p2)
160 | End If
161 |
162 | End Function
163 |
164 | '''
165 | ''' Get intersection of plane with sphere.
166 | ''' Returns object of type 'Nothing', 'Point3d' or 'Circle3d'.
167 | '''
168 | Public Function IntersectionWith(s As Plane3d) As Object
169 |
170 | s.SetCoord(Me.Center.Coord)
171 | Dim d1 As Double = s.A * Me.X + s.B * Me.Y + s.C * Me.Z + s.D
172 | Dim d2 As Double = s.A ^ 2 + s.B ^ 2 + s.C ^ 2
173 | Dim d As Double = Abs(d1) / Sqrt(d2)
174 |
175 | If d > Me.R + GeometRi3D.Tolerance Then
176 | Return Nothing
177 | Else
178 | Dim Xc As Double = Me.X - s.A * d1 / d2
179 | Dim Yc As Double = Me.Y - s.B * d1 / d2
180 | Dim Zc As Double = Me.Z - s.C * d1 / d2
181 |
182 | If Abs(d - Me.R) < GeometRi3D.Tolerance Then
183 | Return New Point3d(Xc, Yc, Zc, Me.Center.Coord)
184 | Else
185 | Dim R As Double = Sqrt(Me.R ^ 2 - d ^ 2)
186 | Return New Circle3d(New Point3d(Xc, Yc, Zc, Me.Center.Coord), R, s.Normal)
187 | End If
188 | End If
189 | End Function
190 |
191 | '''
192 | ''' Get intersection of two spheres.
193 | ''' Returns object of type 'Nothing', 'Point3d' or 'Circle3d'.
194 | '''
195 | Public Function IntersectionWith(s As Sphere) As Object
196 |
197 | Dim p As Point3d = s.Center.ConvertTo(Me.Center.Coord)
198 | Dim Dist As Double = Sqrt((Me.X - p.X) ^ 2 + (Me.Y - p.Y) ^ 2 + (Me.Z - p.Z) ^ 2)
199 |
200 | ' Separated spheres
201 | If Dist > Me.R + s.R + GeometRi3D.Tolerance Then Return Nothing
202 |
203 | ' One sphere inside the other
204 | If Dist < Abs(Me.R - s.R) - GeometRi3D.Tolerance Then Return Nothing
205 |
206 | ' Intersection plane
207 | Dim A As Double = 2 * (p.X - Me.X)
208 | Dim B As Double = 2 * (p.Y - Me.Y)
209 | Dim C As Double = 2 * (p.Z - Me.Z)
210 | Dim D As Double = Me.X ^ 2 - p.X ^ 2 + Me.Y ^ 2 - p.Y ^ 2 + Me.Z ^ 2 - p.Z ^ 2 - Me.R ^ 2 + s.R ^ 2
211 |
212 | ' Intersection center
213 | Dim t As Double = (Me.X * A + Me.Y * B + Me.Z * C + D) / (A * (Me.X - p.X) + B * (Me.Y - p.Y) + C * (Me.Z - p.Z))
214 | Dim x As Double = Me.X + t * (p.X - Me.X)
215 | Dim y As Double = Me.Y + t * (p.Y - Me.Y)
216 | Dim z As Double = Me.Z + t * (p.Z - Me.Z)
217 |
218 | ' Outer tangency
219 | If Abs(Me.R + s.R - D) < GeometRi3D.Tolerance Then Return New Point3d(x, y, z, Me.Center.Coord)
220 |
221 | ' Inner tangency
222 | If Abs(Abs(Me.R - s.R) - D) < GeometRi3D.Tolerance Then Return New Point3d(x, y, z, Me.Center.Coord)
223 |
224 | ' Intersection
225 | Dim alpha As Double = Acos((Me.R ^ 2 + Dist ^ 2 - s.R ^ 2) / (2 * Me.R * Dist))
226 | Dim R As Double = Me.R * Sin(alpha)
227 | Dim v As Vector3d = New Vector3d(Me.Center, s.Center)
228 |
229 | Return New Circle3d(New Point3d(x, y, z, Me.Center.Coord), R, v)
230 |
231 | End Function
232 | #End Region
233 |
234 | '''
235 | ''' Orthogonal projection of the sphere to the plane
236 | '''
237 | Public Function ProjectionTo(s As Plane3d) As Circle3d
238 | Dim p As Point3d = Me.Center.ProjectionTo(s)
239 | Return New Circle3d(p, Me.R, s.Normal)
240 | End Function
241 |
242 | '''
243 | ''' Orthogonal projection of the sphere to the line
244 | '''
245 | Public Function ProjectionTo(l As Line3d) As Segment3d
246 | Dim p As Point3d = Me.Center.ProjectionTo(l)
247 | Return New Segment3d(p.Translate(Me.R * l.Direction.Normalized), p.Translate(-Me.R * l.Direction.Normalized))
248 | End Function
249 |
250 | #Region "TranslateRotateReflect"
251 | '''
252 | ''' Translate sphere by a vector
253 | '''
254 | Public Function Translate(v As Vector3d) As Sphere
255 | Return New Sphere(Me.Center.Translate(v), Me.R)
256 | End Function
257 |
258 | '''
259 | ''' Rotate sphere by a given rotation matrix
260 | '''
261 | Public Function Rotate(ByVal m As Matrix3d) As Sphere
262 | Return New Sphere(Me.Center.Rotate(m), Me.R)
263 | End Function
264 |
265 | '''
266 | ''' Rotate sphere by a given rotation matrix around point 'p' as a rotation center
267 | '''
268 | Public Function Rotate(m As Matrix3d, p As Point3d) As Sphere
269 | Return New Sphere(Me.Center.Rotate(m, p), Me.R)
270 | End Function
271 |
272 | '''
273 | ''' Reflect sphere in given point
274 | '''
275 | Public Function ReflectIn(p As Point3d) As Sphere
276 | Return New Sphere(Me.Center.ReflectIn(p), Me.R)
277 | End Function
278 |
279 | '''
280 | ''' Reflect sphere in given line
281 | '''
282 | Public Function ReflectIn(l As Line3d) As Sphere
283 | Return New Sphere(Me.Center.ReflectIn(l), Me.R)
284 | End Function
285 |
286 | '''
287 | ''' Reflect sphere in given plane
288 | '''
289 | Public Function ReflectIn(s As Plane3d) As Sphere
290 | Return New Sphere(Me.Center.ReflectIn(s), Me.R)
291 | End Function
292 | #End Region
293 |
294 | Public Overloads Overrides Function Equals(obj As Object) As Boolean
295 | If obj Is Nothing OrElse Not Me.GetType() Is obj.GetType() Then
296 | Return False
297 | End If
298 | Dim s As Sphere = CType(obj, Sphere)
299 |
300 | Return s.Center = Me.Center AndAlso Abs(s.R - Me.R) <= GeometRi3D.Tolerance
301 | End Function
302 |
303 | Public Overrides Function GetHashCode() As Integer
304 | Return GeometRi3D.HashFunction(_point.GetHashCode, _r.GetHashCode)
305 | End Function
306 |
307 | Public Overloads Function ToString(Optional coord As Coord3d = Nothing) As String
308 | Dim p As Point3d = _point.ConvertToGlobal
309 | If coord IsNot Nothing Then p = p.ConvertTo(coord)
310 |
311 | Dim str As String = String.Format("Sphere: ") + vbCrLf
312 | str += String.Format(" Center -> ({0,10:g5}, {1,10:g5}, {2,10:g5})", p.X, p.Y, p.Z) + vbCrLf
313 | str += String.Format(" Radius -> {0,10:g5}", _r)
314 | Return str
315 | End Function
316 |
317 | ' Operators overloads
318 | '-----------------------------------------------------------------
319 |
320 | Public Shared Operator =(s1 As Sphere, s2 As Sphere) As Boolean
321 | Return s1.Equals(s2)
322 | End Operator
323 | Public Shared Operator <>(s1 As Sphere, s2 As Sphere) As Boolean
324 | Return Not s1.Equals(s2)
325 | End Operator
326 |
327 | End Class
328 |
--------------------------------------------------------------------------------
/GeometRi/GeometRi/Triangle.vb:
--------------------------------------------------------------------------------
1 | Imports System.Math
2 |
3 | Public Class Triangle
4 |
5 | Implements ICloneable
6 |
7 | Private _a As Point3d
8 | Private _b As Point3d
9 | Private _c As Point3d
10 |
11 | Public Sub New(A As Point3d, B As Point3d, C As Point3d)
12 | If Point3d.CollinearPoints(A, B, C) Then
13 | Throw New Exception("Collinear points")
14 | End If
15 | _a = A.Clone
16 | _b = B.Clone
17 | _c = C.Clone
18 | End Sub
19 |
20 |
21 | Public Function Clone() As Object Implements ICloneable.Clone
22 | Dim newobj As Triangle = DirectCast(MemberwiseClone(), Triangle)
23 | newobj.A = newobj.A.Clone
24 | newobj.B = newobj.B.Clone
25 | newobj.C = newobj.C.Clone
26 | Return newobj
27 | End Function
28 |
29 | #Region "Properties"
30 | '''
31 | ''' First point of triangle
32 | '''
33 | Public Property A As Point3d
34 | Get
35 | Return _a.Clone
36 | End Get
37 | Set(value As Point3d)
38 | If Point3d.CollinearPoints(value, _b, _c) Then
39 | Throw New Exception("Collinear points")
40 | End If
41 | _a = value.Clone
42 | End Set
43 | End Property
44 |
45 | '''
46 | ''' Second point of triangle
47 | '''
48 | Public Property B As Point3d
49 | Get
50 | Return _b.Clone
51 | End Get
52 | Set(value As Point3d)
53 | If Point3d.CollinearPoints(_a, value, _c) Then
54 | Throw New Exception("Collinear points")
55 | End If
56 | _b = value.Clone
57 | End Set
58 | End Property
59 |
60 | '''
61 | ''' Third point of triangle
62 | '''
63 | Public Property C As Point3d
64 | Get
65 | Return _c.Clone
66 | End Get
67 | Set(value As Point3d)
68 | If Point3d.CollinearPoints(_a, _b, value) Then
69 | Throw New Exception("Collinear points")
70 | End If
71 | _c = value.Clone
72 | End Set
73 | End Property
74 |
75 | '''
76 | ''' Length of AB side
77 | '''
78 | Public ReadOnly Property AB As Double
79 | Get
80 | Return _a.DistanceTo(_b)
81 | End Get
82 | End Property
83 |
84 | '''
85 | ''' Length of AC side
86 | '''
87 | Public ReadOnly Property AC As Double
88 | Get
89 | Return _a.DistanceTo(_c)
90 | End Get
91 | End Property
92 |
93 | '''
94 | ''' Length of BC side
95 | '''
96 | Public ReadOnly Property BC As Double
97 | Get
98 | Return _b.DistanceTo(_c)
99 | End Get
100 | End Property
101 |
102 | '''
103 | ''' Perimeter of the triangle
104 | '''
105 | Public ReadOnly Property Perimeter As Double
106 | Get
107 | Return AB + BC + AC
108 | End Get
109 | End Property
110 |
111 | '''
112 | ''' Area of the triangle
113 | '''
114 | Public ReadOnly Property Area As Double
115 | Get
116 | Dim v1 = New Vector3d(_a, _b)
117 | Dim v2 = New Vector3d(_a, _c)
118 | Return 0.5 * v1.Cross(v2).Norm
119 | End Get
120 | End Property
121 |
122 | '''
123 | ''' Circumcircle of the triangle
124 | '''
125 | Public ReadOnly Property Circumcircle As Circle3d
126 | Get
127 | Return New Circle3d(_a, _b, _c)
128 | End Get
129 | End Property
130 |
131 | '''
132 | ''' Angle at the vertex A
133 | '''
134 | Public ReadOnly Property Angle_A As Double
135 | Get
136 | Return New Vector3d(_a, _b).AngleTo(New Vector3d(_a, _c))
137 | End Get
138 | End Property
139 |
140 | '''
141 | ''' Angle at the vertex B
142 | '''
143 | Public ReadOnly Property Angle_B As Double
144 | Get
145 | Return New Vector3d(_b, _a).AngleTo(New Vector3d(_b, _c))
146 | End Get
147 | End Property
148 |
149 | '''
150 | ''' Angle at the vertex C
151 | '''
152 | Public ReadOnly Property Angle_C As Double
153 | Get
154 | Return New Vector3d(_c, _a).AngleTo(New Vector3d(_c, _b))
155 | End Get
156 | End Property
157 |
158 | '''
159 | ''' Angle bisector at the vertex A
160 | '''
161 | Public ReadOnly Property Bisector_A As Segment3d
162 | Get
163 | Dim p As Point3d = _b + (_c - _b) / (1 + AC / AB)
164 | Return New Segment3d(_a, p)
165 | End Get
166 | End Property
167 |
168 | '''
169 | ''' Angle bisector at the vertex B
170 | '''
171 | Public ReadOnly Property Bisector_B As Segment3d
172 | Get
173 | Dim p As Point3d = _c + (_a - _c) / (1 + AB / BC)
174 | Return New Segment3d(_b, p)
175 | End Get
176 | End Property
177 |
178 | '''
179 | ''' Angle bisector at the vertex C
180 | '''
181 | Public ReadOnly Property Bisector_C As Segment3d
182 | Get
183 | Dim p As Point3d = _a + (_b - _a) / (1 + BC / AC)
184 | Return New Segment3d(_c, p)
185 | End Get
186 | End Property
187 |
188 | '''
189 | ''' Incenter of the triangle
190 | '''
191 | Public ReadOnly Property Incenter As Point3d
192 | Get
193 | Return Bisector_A.ToLine.PerpendicularTo(Bisector_B.ToLine)
194 | End Get
195 | End Property
196 |
197 | '''
198 | ''' Centroid of the triangle
199 | '''
200 | Public ReadOnly Property Centroid As Point3d
201 | Get
202 | Return New Point3d((A.X + B.X + C.X) / 3, (A.Y + B.Y + C.Y) / 3, (A.Z + B.Z + C.Z) / 3)
203 | End Get
204 | End Property
205 |
206 | '''
207 | ''' Orthocenter of the triangle
208 | '''
209 | Public ReadOnly Property Orthocenter As Point3d
210 | Get
211 | Return Altitude_A.ToLine.PerpendicularTo(Altitude_B.ToLine)
212 | End Get
213 | End Property
214 |
215 | '''
216 | ''' Circumcenter of the triangle
217 | '''
218 | Public ReadOnly Property Circumcenter As Point3d
219 | Get
220 | Return New Circle3d(_a, _b, _c).Center
221 | End Get
222 | End Property
223 |
224 | '''
225 | ''' Incircle of the triangle
226 | '''
227 | Public ReadOnly Property Incircle As Circle3d
228 | Get
229 | Dim p As Point3d = Bisector_A.ToLine.PerpendicularTo(Bisector_B.ToLine)
230 | Dim r As Double = 2 * Area / Perimeter
231 | Dim v As Vector3d = New Vector3d(_a, _b).Cross(New Vector3d(_a, _c))
232 | Return New Circle3d(p, r, v)
233 | End Get
234 | End Property
235 |
236 | '''
237 | ''' Altitude at the vertex A
238 | '''
239 | Public ReadOnly Property Altitude_A As Segment3d
240 | Get
241 | Dim p As Point3d = _a.ProjectionTo(New Line3d(_b, _c))
242 | Return New Segment3d(_a, p)
243 | End Get
244 | End Property
245 |
246 | '''
247 | ''' Altitude at the vertex B
248 | '''
249 | Public ReadOnly Property Altitude_B As Segment3d
250 | Get
251 | Dim p As Point3d = _b.ProjectionTo(New Line3d(_a, _c))
252 | Return New Segment3d(_b, p)
253 | End Get
254 | End Property
255 |
256 | '''
257 | ''' Altitude at the vertex C
258 | '''
259 | Public ReadOnly Property Altitude_C As Segment3d
260 | Get
261 | Dim p As Point3d = _c.ProjectionTo(New Line3d(_a, _b))
262 | Return New Segment3d(_c, p)
263 | End Get
264 | End Property
265 |
266 | '''
267 | ''' Median at the vertex A
268 | '''
269 | Public ReadOnly Property Median_A As Segment3d
270 | Get
271 | Return New Segment3d(_a, (_b + _c) / 2)
272 | End Get
273 | End Property
274 |
275 | '''
276 | ''' Median at the vertex B
277 | '''
278 | Public ReadOnly Property Median_B As Segment3d
279 | Get
280 | Return New Segment3d(_b, (_a + _c) / 2)
281 | End Get
282 | End Property
283 |
284 | '''
285 | ''' Median at the vertex C
286 | '''
287 | Public ReadOnly Property Median_C As Segment3d
288 | Get
289 | Return New Segment3d(_c, (_a + _b) / 2)
290 | End Get
291 | End Property
292 | #End Region
293 |
294 | #Region "TriangleProperties"
295 | '''
296 | ''' True if all sides of the triangle are the same length
297 | '''
298 | Public ReadOnly Property IsEquilateral As Boolean
299 | Get
300 | Return GeometRi3D.AlmostEqual(AB, AC) AndAlso GeometRi3D.AlmostEqual(AB, BC)
301 | End Get
302 | End Property
303 |
304 | '''
305 | ''' True if two sides of the triangle are the same length
306 | '''
307 | Public ReadOnly Property IsIsosceles As Boolean
308 | Get
309 | Return GeometRi3D.AlmostEqual(AB, AC) OrElse
310 | GeometRi3D.AlmostEqual(AB, BC) OrElse
311 | GeometRi3D.AlmostEqual(AC, BC)
312 | End Get
313 | End Property
314 |
315 | '''
316 | ''' True if all sides are unequal
317 | '''
318 | Public ReadOnly Property IsScalene As Boolean
319 | Get
320 | Return GeometRi3D.NotEqual(AB, AC) AndAlso
321 | GeometRi3D.NotEqual(AB, BC) AndAlso
322 | GeometRi3D.NotEqual(AC, BC)
323 | End Get
324 | End Property
325 |
326 | '''
327 | ''' True if one angle is equal 90 degrees
328 | '''
329 | Public ReadOnly Property IsRight As Boolean
330 | Get
331 | Return GeometRi3D.AlmostEqual(Angle_A, PI / 2) OrElse
332 | GeometRi3D.AlmostEqual(Angle_B, PI / 2) OrElse
333 | GeometRi3D.AlmostEqual(Angle_C, PI / 2)
334 | End Get
335 | End Property
336 |
337 | '''
338 | ''' True if one angle is greater than 90 degrees
339 | '''
340 | Public ReadOnly Property IsObtuse As Boolean
341 | Get
342 | Return GeometRi3D.Greater(Angle_A, PI / 2) OrElse
343 | GeometRi3D.Greater(Angle_B, PI / 2) OrElse
344 | GeometRi3D.Greater(Angle_C, PI / 2)
345 | End Get
346 | End Property
347 |
348 | '''
349 | ''' True if all angles are less than 90 degrees
350 | '''
351 | Public ReadOnly Property IsAcute As Boolean
352 | Get
353 | Return GeometRi3D.Smaller(Angle_A, PI / 2) AndAlso
354 | GeometRi3D.Smaller(Angle_B, PI / 2) AndAlso
355 | GeometRi3D.Smaller(Angle_C, PI / 2)
356 | End Get
357 | End Property
358 | #End Region
359 |
360 | #Region "TranslateRotateReflect"
361 | '''
362 | ''' Translate triangle by a vector
363 | '''
364 | Public Function Translate(v As Vector3d) As Triangle
365 | Return New Triangle(_a.Translate(v), _b.Translate(v), _c.Translate(v))
366 | End Function
367 |
368 | '''
369 | ''' Rotate triangle by a given rotation matrix
370 | '''
371 | Public Function Rotate(ByVal m As Matrix3d) As Triangle
372 | Return New Triangle(_a.Rotate(m), _b.Rotate(m), _c.Rotate(m))
373 | End Function
374 |
375 | '''
376 | ''' Rotate triangle by a given rotation matrix around point 'p' as a rotation center
377 | '''
378 | Public Function Rotate(m As Matrix3d, p As Point3d) As Triangle
379 | Return New Triangle(_a.Rotate(m, p), _b.Rotate(m, p), _c.Rotate(m, p))
380 | End Function
381 |
382 | '''
383 | ''' Reflect triangle in given point
384 | '''
385 | Public Function ReflectIn(p As Point3d) As Triangle
386 | Return New Triangle(_a.ReflectIn(p), _b.ReflectIn(p), _c.ReflectIn(p))
387 | End Function
388 |
389 | '''
390 | ''' Reflect triangle in given line
391 | '''
392 | Public Function ReflectIn(l As Line3d) As Triangle
393 | Return New Triangle(_a.ReflectIn(l), _b.ReflectIn(l), _c.ReflectIn(l))
394 | End Function
395 |
396 | '''
397 | ''' Reflect triangle in given plane
398 | '''
399 | Public Function ReflectIn(s As Plane3d) As Triangle
400 | Return New Triangle(_a.ReflectIn(s), _b.ReflectIn(s), _c.ReflectIn(s))
401 | End Function
402 | #End Region
403 |
404 | Public Overloads Overrides Function Equals(obj As Object) As Boolean
405 | If obj Is Nothing OrElse Not Me.GetType() Is obj.GetType() Then
406 | Return False
407 | End If
408 | Dim t As Triangle = CType(obj, Triangle)
409 |
410 | If (Me.A = t.A OrElse Me.A = t.B OrElse Me.A = t.C) AndAlso
411 | (Me.B = t.A OrElse Me.B = t.B OrElse Me.B = t.C) AndAlso
412 | (Me.C = t.A OrElse Me.C = t.B OrElse Me.C = t.C) Then
413 | Return True
414 | Else
415 | Return False
416 | End If
417 | End Function
418 |
419 | Public Overrides Function GetHashCode() As Integer
420 | Return GeometRi3D.HashFunction(_a.GetHashCode, _b.GetHashCode, _c.GetHashCode)
421 | End Function
422 |
423 | Public Overloads Function ToString(Optional coord As Coord3d = Nothing) As String
424 | Dim str As New System.Text.StringBuilder
425 | Dim A, B, C As Point3d
426 | If coord IsNot Nothing Then
427 | A = _a.ConvertTo(coord)
428 | B = _b.ConvertTo(coord)
429 | C = _c.ConvertTo(coord)
430 | Else
431 | A = _a.ConvertToGlobal
432 | B = _b.ConvertToGlobal
433 | C = _c.ConvertToGlobal
434 | End If
435 | str.Append("Triangle:" + vbCrLf)
436 | str.Append(String.Format("A -> ({0,10:g5}, {1,10:g5}, {2,10:g5})", A.X, A.Y, A.Z) + vbCrLf)
437 | str.Append(String.Format("B -> ({0,10:g5}, {1,10:g5}, {2,10:g5})", B.X, B.Y, B.Z) + vbCrLf)
438 | str.Append(String.Format("C -> ({0,10:g5}, {1,10:g5}, {2,10:g5})", C.X, C.Y, C.Z))
439 | Return str.ToString
440 | End Function
441 |
442 | ' Operators overloads
443 | '-----------------------------------------------------------------
444 |
445 | Public Shared Operator =(t1 As Triangle, t2 As Triangle) As Boolean
446 | Return t1.Equals(t2)
447 | End Operator
448 | Public Shared Operator <>(t1 As Triangle, t2 As Triangle) As Boolean
449 | Return Not t1.Equals(t2)
450 | End Operator
451 | End Class
452 |
--------------------------------------------------------------------------------
/GeometRi/GeometRi/Vector3D.vb:
--------------------------------------------------------------------------------
1 | Imports System.Math
2 |
3 | Public Class Vector3d
4 | Implements ICloneable
5 |
6 | Private val(2) As Double
7 | Private _coord As Coord3d
8 |
9 | #Region "Constructors"
10 | Public Sub New(Optional coord As Coord3d = Nothing)
11 | Me.val(0) = 0.0
12 | Me.val(1) = 0.0
13 | Me.val(2) = 0.0
14 | If coord IsNot Nothing Then
15 | _coord = coord
16 | Else
17 | _coord = Coord3d.GlobalCS
18 | End If
19 | End Sub
20 | Public Sub New(ByVal X As Double, ByVal Y As Double, ByVal Z As Double, Optional coord As Coord3d = Nothing)
21 | Me.val(0) = X
22 | Me.val(1) = Y
23 | Me.val(2) = Z
24 | If coord IsNot Nothing Then
25 | _coord = coord
26 | Else
27 | _coord = Coord3d.GlobalCS
28 | End If
29 | End Sub
30 | Public Sub New(ByVal p As Point3d)
31 | Me.val(0) = p.X
32 | Me.val(1) = p.Y
33 | Me.val(2) = p.Z
34 | _coord = p.Coord
35 | End Sub
36 | Public Sub New(ByVal p1 As Point3d, ByVal p2 As Point3d)
37 | If p1.Coord <> p2.Coord Then p2 = p2.ConvertTo(p1.Coord)
38 | Me.val(0) = p2.X - p1.X
39 | Me.val(1) = p2.Y - p1.Y
40 | Me.val(2) = p2.Z - p1.Z
41 | _coord = p1.Coord
42 | End Sub
43 | Public Sub New(a() As Double, Optional coord As Coord3d = Nothing)
44 | If a.GetUpperBound(0) < 2 Then Throw New Exception("Vector3d: Array size mismatch")
45 | Me.val(0) = a(0)
46 | Me.val(1) = a(1)
47 | Me.val(2) = a(2)
48 | If coord IsNot Nothing Then
49 | _coord = coord
50 | Else
51 | _coord = Coord3d.GlobalCS
52 | End If
53 | End Sub
54 | #End Region
55 |
56 |
57 |
58 | Public Function Clone() As Object Implements ICloneable.Clone
59 | Dim newvec As Vector3d = DirectCast(MemberwiseClone(), Vector3d)
60 | newvec.val = newvec.val.Clone
61 | Return newvec
62 | End Function
63 |
64 | Default Public Property Item(i As Integer) As Double
65 | Get
66 | Return val(i)
67 | End Get
68 | Set(value As Double)
69 | val(i) = value
70 | End Set
71 | End Property
72 |
73 | '''
74 | ''' X component in reference coordinate system
75 | '''
76 | Public Property X As Double
77 | Get
78 | Return val(0)
79 | End Get
80 | Set(value As Double)
81 | val(0) = value
82 | End Set
83 | End Property
84 |
85 | '''
86 | ''' Y component in reference coordinate system
87 | '''
88 | Public Property Y As Double
89 | Get
90 | Return val(1)
91 | End Get
92 | Set(value As Double)
93 | val(1) = value
94 | End Set
95 | End Property
96 |
97 | '''
98 | ''' Z component in reference coordinate system
99 | '''
100 | Public Property Z As Double
101 | Get
102 | Return val(2)
103 | End Get
104 | Set(value As Double)
105 | val(2) = value
106 | End Set
107 | End Property
108 |
109 | '''
110 | ''' Norm of a vector
111 | '''
112 | Public ReadOnly Property Norm As Double
113 | Get
114 | Return Sqrt(val(0) ^ 2 + val(1) ^ 2 + val(2) ^ 2)
115 | End Get
116 | End Property
117 |
118 | '''
119 | ''' Reference coordinate system
120 | '''
121 | Public ReadOnly Property Coord As Coord3d
122 | Get
123 | Coord = _coord
124 | End Get
125 | End Property
126 |
127 | '''
128 | ''' Point, represented by vector starting in origin
129 | '''
130 | Public ReadOnly Property ToPoint As Point3d
131 | Get
132 | Return New Point3d(val(0), val(1), val(2), _coord)
133 | End Get
134 | End Property
135 |
136 | '''
137 | ''' Normalize the current vector
138 | '''
139 | Public Sub Normalize()
140 | Dim tmp As Double = 1.0 / Me.Norm
141 | val(0) = val(0) * tmp
142 | val(1) = val(1) * tmp
143 | val(2) = val(2) * tmp
144 | End Sub
145 |
146 | '''
147 | ''' Return normalized vector
148 | '''
149 | Public Function Normalized() As Vector3d
150 | Dim tmp As Vector3d = Me.Clone
151 | Dim tmp_norm As Double = Me.Norm
152 | tmp.val(0) = val(0) / tmp_norm
153 | tmp.val(1) = val(1) / tmp_norm
154 | tmp.val(2) = val(2) / tmp_norm
155 | Return tmp
156 | End Function
157 |
158 | '''
159 | ''' Check if two vectors are parallel
160 | '''
161 | Public Function IsParallelTo(v As Vector3d) As Boolean
162 | If (Me._coord <> v._coord) Then v = v.ConvertTo(Me._coord)
163 | Return Me.Cross(v).Norm < GeometRi3D.Tolerance
164 | End Function
165 |
166 | '''
167 | ''' Check if two vectors are NOT parallel
168 | '''
169 | Public Function IsNotParallelTo(v As Vector3d) As Boolean
170 | If (Me._coord <> v._coord) Then v = v.ConvertTo(Me._coord)
171 | Return Me.Cross(v).Norm >= GeometRi3D.Tolerance
172 | End Function
173 |
174 | '''
175 | ''' Check if two vectors are orthogonal
176 | '''
177 | Public Function IsOrthogonalTo(v As Vector3d) As Boolean
178 | If (Me._coord <> v._coord) Then v = v.ConvertTo(Me._coord)
179 | Return Abs(Me * v) < GeometRi3D.Tolerance
180 | End Function
181 |
182 | Public Function Add(ByVal a As Double) As Vector3d
183 | Dim tmp As Vector3d = Me.Clone
184 | tmp.val(0) += a
185 | tmp.val(1) += a
186 | tmp.val(2) += a
187 | Return tmp
188 | End Function
189 | Public Function Add(ByVal v As Vector3d) As Vector3d
190 | If (Me._coord <> v._coord) Then v = v.ConvertTo(Me._coord)
191 | Dim tmp As Vector3d = Me.Clone
192 | tmp.val(0) += v.X
193 | tmp.val(1) += v.Y
194 | tmp.val(2) += v.Z
195 | Return tmp
196 | End Function
197 | Public Function Subtract(ByVal a As Double) As Vector3d
198 | Dim tmp As Vector3d = Me.Clone
199 | tmp.val(0) -= a
200 | tmp.val(1) -= a
201 | tmp.val(2) -= a
202 | Return tmp
203 | End Function
204 | Public Function Subtract(ByVal v As Vector3d) As Vector3d
205 | If (Me._coord <> v._coord) Then v = v.ConvertTo(Me._coord)
206 | Dim tmp As Vector3d = Me.Clone
207 | tmp.val(0) -= v.X
208 | tmp.val(1) -= v.Y
209 | tmp.val(2) -= v.Z
210 | Return tmp
211 | End Function
212 | Public Function Mult(ByVal a As Double) As Vector3d
213 | Dim tmp As Vector3d = Me.Clone
214 | tmp.val(0) *= a
215 | tmp.val(1) *= a
216 | tmp.val(2) *= a
217 | Return tmp
218 | End Function
219 |
220 | '''
221 | ''' Dot product of two vectors
222 | '''
223 | Public Function Dot(ByVal v As Vector3d) As Double
224 | If (Me._coord <> v._coord) Then v = v.ConvertTo(Me._coord)
225 | Return Me.val(0) * v.val(0) + Me.val(1) * v.val(1) + Me.val(2) * v.val(2)
226 | End Function
227 |
228 | '''
229 | ''' Cross product of two vectors
230 | '''
231 | Public Function Cross(ByVal v As Vector3d) As Vector3d
232 | If (Me._coord <> v._coord) Then v = v.ConvertTo(Me._coord)
233 | Dim tmp As Vector3d = New Vector3d(0, 0, 0, _coord)
234 | tmp.X = Me.Y * v.Z - Me.Z * v.Y
235 | tmp.Y = Me.Z * v.X - Me.X * v.Z
236 | tmp.Z = Me.X * v.Y - Me.Y * v.X
237 | Return tmp
238 | End Function
239 |
240 | '''
241 | ''' Convert vector to local coordinate system.
242 | '''
243 | Public Function ConvertTo(ByVal coord As Coord3d) As Vector3d
244 | Dim v1 As Vector3d = Me.Clone
245 | v1 = v1.ConvertToGlobal()
246 | If coord IsNot Nothing AndAlso coord IsNot Coord3d.GlobalCS Then
247 | v1 = coord.Axes * v1
248 | v1._coord = coord
249 | End If
250 | Return v1
251 | End Function
252 |
253 | '''
254 | ''' Convert vector to global coordinate system
255 | '''
256 | Public Function ConvertToGlobal() As Vector3d
257 | If _coord Is Nothing OrElse _coord Is Coord3d.GlobalCS Then
258 | Return Me
259 | Else
260 | Dim v As Vector3d = Me.Clone
261 | v = _coord.Axes.Inverse * v
262 | v._coord = Coord3d.GlobalCS
263 | Return v
264 | End If
265 | End Function
266 |
267 | #Region "AngleTo"
268 | '''
269 | ''' Angle between two vectors in radians (0 < angle < Pi)
270 | '''
271 | Public Function AngleTo(v As Vector3d) As Double
272 | If (Me._coord <> v._coord) Then v = v.ConvertTo(Me._coord)
273 | Return Acos(Me.Dot(v) / Me.Norm / v.Norm)
274 | End Function
275 | '''
276 | ''' Angle between two vectors in degrees (0 < angle < 180)
277 | '''
278 | Public Function AngleToDeg(v As Vector3d) As Double
279 | Return AngleTo(v) * 180 / PI
280 | End Function
281 |
282 | '''
283 | ''' Angle between vector and ray in radians (0 < angle < Pi)
284 | '''
285 | Public Function AngleTo(r As Ray3d) As Double
286 | Return Me.AngleTo(r.Direction)
287 | End Function
288 | '''
289 | ''' Angle between vector and ray in degrees (0 < angle < 180)
290 | '''
291 | Public Function AngleToDeg(r As Ray3d) As Double
292 | Return Me.AngleTo(r.Direction) * 180 / PI
293 | End Function
294 |
295 | '''
296 | ''' Smalest angle between vector and line in radians (0 < angle < Pi/2)
297 | '''
298 | Public Function AngleTo(l As Line3d) As Double
299 | Dim ang As Double = Me.AngleTo(l.Direction)
300 | If ang <= PI / 2 Then
301 | Return ang
302 | Else
303 | Return PI - ang
304 | End If
305 | End Function
306 | '''
307 | ''' Smalest angle between vector and line in degrees (0 < angle < 90)
308 | '''
309 | Public Function AngleToDeg(l As Line3d) As Double
310 | Return AngleTo(l) * 180 / PI
311 | End Function
312 |
313 | '''
314 | ''' Smalest angle between vector and segment in radians (0 < angle < Pi/2)
315 | '''
316 | Public Function AngleTo(s As Segment3d) As Double
317 | Dim ang As Double = Me.AngleTo(s.ToVector)
318 | If ang <= PI / 2 Then
319 | Return ang
320 | Else
321 | Return PI - ang
322 | End If
323 | End Function
324 | '''
325 | ''' Smalest angle between vector and segment in degrees (0 < angle < 90)
326 | '''
327 | Public Function AngleToDeg(s As Segment3d) As Double
328 | Return AngleTo(s) * 180 / PI
329 | End Function
330 |
331 | '''
332 | ''' Smalest angle between vector and plane in radians (0 < angle < Pi/2)
333 | '''
334 | Public Function AngleTo(s As Plane3d) As Double
335 | Dim ang As Double = Asin(Me.Dot(s.Normal) / Me.Norm / s.Normal.Norm)
336 | Return Abs(ang)
337 | End Function
338 | '''
339 | ''' Smalest angle between vector and plane in degrees (0 < angle < 90)
340 | '''
341 | Public Function AngleToDeg(s As Plane3d) As Double
342 | Return AngleTo(s) * 180 / PI
343 | End Function
344 | #End Region
345 |
346 | '''
347 | ''' Return projection of the current vector to the second vector
348 | '''
349 | Public Function ProjectionTo(v As Vector3d) As Vector3d
350 | If (Me._coord <> v._coord) Then v = v.ConvertTo(Me._coord)
351 | Return (Me * v) / (v * v) * v
352 | End Function
353 |
354 | '''
355 | ''' Return arbitrary vector, orthogonal to the current vector
356 | '''
357 | Public ReadOnly Property OrthogonalVector As Vector3d
358 | Get
359 | If Abs(Me.X) <= Abs(Me.Y) AndAlso Abs(Me.X) <= Abs(Me.Z) Then
360 | Return New Vector3d(0, Me.Z, -Me.Y, Me.Coord)
361 | ElseIf Abs(Me.Y) <= Abs(Me.X) AndAlso Abs(Me.Y) <= Abs(Me.Z) Then
362 | Return New Vector3d(Me.Z, 0, -Me.X, Me.Coord)
363 | Else
364 | Return New Vector3d(Me.Y, -Me.X, 0, Me.Coord)
365 | End If
366 | End Get
367 | End Property
368 |
369 | #Region "RotateReflect"
370 | '''
371 | ''' Rotate vector by a given rotation matrix
372 | '''
373 | Public Function Rotate(ByVal m As Matrix3d) As Vector3d
374 | Return m * Me
375 | End Function
376 |
377 | '''
378 | ''' Reflect vector in given point
379 | '''
380 | Public Function ReflectIn(p As Point3d) As Vector3d
381 | Return -Me
382 | End Function
383 |
384 | '''
385 | ''' Reflect vector in given line
386 | '''
387 | Public Function ReflectIn(l As Line3d) As Vector3d
388 | Dim p1 As Point3d = New Point3d(0, 0, 0, Me._coord)
389 | Dim p2 As Point3d = p1.Translate(Me)
390 | Return New Vector3d(p1.ReflectIn(l), p2.ReflectIn(l))
391 | End Function
392 |
393 | '''
394 | ''' Reflect vector in given plane
395 | '''
396 | Public Function ReflectIn(s As Plane3d) As Vector3d
397 | Dim p1 As Point3d = New Point3d(0, 0, 0, Me._coord)
398 | Dim p2 As Point3d = p1.Translate(Me)
399 | Return New Vector3d(p1.ReflectIn(s), p2.ReflectIn(s))
400 | End Function
401 | #End Region
402 |
403 | Public Overloads Overrides Function Equals(obj As Object) As Boolean
404 | If obj Is Nothing OrElse Not Me.GetType() Is obj.GetType() Then
405 | Return False
406 | End If
407 | Dim v As Vector3d = CType(obj, Vector3d)
408 | If (Me._coord <> v.Coord) Then v = v.ConvertTo(_coord)
409 | Return Abs(Me.X - v.X) < GeometRi3D.Tolerance AndAlso Abs(Me.Y - v.Y) < GeometRi3D.Tolerance AndAlso Abs(Me.Y - v.Y) < GeometRi3D.Tolerance
410 | End Function
411 |
412 | Public Overrides Function GetHashCode() As Integer
413 | Return GeometRi3D.HashFunction(val(0), val(1), val(2), _coord.GetHashCode)
414 | End Function
415 |
416 | Public Overloads Function ToString(Optional coord As Coord3d = Nothing) As String
417 | Dim v As Vector3d = Me.ConvertToGlobal
418 | If coord IsNot Nothing Then
419 | v = Me.ConvertTo(coord)
420 | End If
421 | Return String.Format("Vector3d -> ({0,10:g5}, {1,10:g5}, {2,10:g5})", v.X, v.Y, v.Z)
422 | End Function
423 |
424 | ' Operators overloads
425 | '-----------------------------------------------------------------
426 | ' "+"
427 | Public Shared Operator +(v As Vector3d, a As Vector3d) As Vector3d
428 | Return v.Add(a)
429 | End Operator
430 | ' "-"
431 | Public Shared Operator -(v As Vector3d) As Vector3d
432 | Return v.Mult(-1.0)
433 | End Operator
434 | Public Shared Operator -(v As Vector3d, a As Vector3d) As Vector3d
435 | Return v.Subtract(a)
436 | End Operator
437 | ' "*"
438 | Public Shared Operator *(v As Vector3d, a As Double) As Vector3d
439 | Return v.Mult(a)
440 | End Operator
441 | Public Shared Operator *(a As Double, v As Vector3d) As Vector3d
442 | Return v.Mult(a)
443 | End Operator
444 | '''
445 | ''' Dot product of two vectors
446 | '''
447 | Public Shared Operator *(v As Vector3d, a As Vector3d) As Double
448 | Return v.Dot(a)
449 | End Operator
450 |
451 | Public Shared Operator =(v1 As Vector3d, v2 As Vector3d) As Boolean
452 | Return v1.Equals(v2)
453 | End Operator
454 | Public Shared Operator <>(v1 As Vector3d, v2 As Vector3d) As Boolean
455 | Return Not v1.Equals(v2)
456 | End Operator
457 |
458 | End Class
459 |
--------------------------------------------------------------------------------
/GeometRi/My Project/Application.Designer.vb:
--------------------------------------------------------------------------------
1 | '------------------------------------------------------------------------------
2 | '
3 | ' This code was generated by a tool.
4 | ' Runtime Version:4.0.30319.42000
5 | '
6 | ' Changes to this file may cause incorrect behavior and will be lost if
7 | ' the code is regenerated.
8 | '
9 | '------------------------------------------------------------------------------
10 |
11 | Option Strict On
12 | Option Explicit On
13 |
14 |
--------------------------------------------------------------------------------
/GeometRi/My Project/Application.myapp:
--------------------------------------------------------------------------------
1 |
2 |
3 | false
4 | false
5 | 0
6 | true
7 | 0
8 | 2
9 | true
10 |
11 |
--------------------------------------------------------------------------------
/GeometRi/My Project/AssemblyInfo.vb:
--------------------------------------------------------------------------------
1 | Imports System
2 | Imports System.Reflection
3 | Imports System.Runtime.InteropServices
4 |
5 | ' General Information about an assembly is controlled through the following
6 | ' set of attributes. Change these attribute values to modify the information
7 | ' associated with an assembly.
8 |
9 | ' Review the values of the assembly attributes
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 | 'The following GUID is for the ID of the typelib if this project is exposed to COM
21 |
22 |
23 | ' Version information for an assembly consists of the following four values:
24 | '
25 | ' Major Version
26 | ' Minor Version
27 | ' Build Number
28 | ' Revision
29 | '
30 | ' You can specify all the values or you can default the Build and Revision Numbers
31 | ' by using the '*' as shown below:
32 | '
33 |
34 |
35 |
36 |
--------------------------------------------------------------------------------
/GeometRi/My Project/Resources.Designer.vb:
--------------------------------------------------------------------------------
1 | '------------------------------------------------------------------------------
2 | '
3 | ' This code was generated by a tool.
4 | ' Runtime Version:4.0.30319.42000
5 | '
6 | ' Changes to this file may cause incorrect behavior and will be lost if
7 | ' the code is regenerated.
8 | '
9 | '------------------------------------------------------------------------------
10 |
11 | Option Strict On
12 | Option Explicit On
13 |
14 | Imports System
15 |
16 | Namespace My.Resources
17 |
18 | 'This class was auto-generated by the StronglyTypedResourceBuilder
19 | 'class via a tool like ResGen or Visual Studio.
20 | 'To add or remove a member, edit your .ResX file then rerun ResGen
21 | 'with the /str option, or rebuild your VS project.
22 | '''
23 | ''' A strongly-typed resource class, for looking up localized strings, etc.
24 | '''
25 | _
29 | Friend Module Resources
30 |
31 | Private resourceMan As Global.System.Resources.ResourceManager
32 |
33 | Private resourceCulture As Global.System.Globalization.CultureInfo
34 |
35 | '''
36 | ''' Returns the cached ResourceManager instance used by this class.
37 | '''
38 | _
39 | Friend ReadOnly Property ResourceManager() As Global.System.Resources.ResourceManager
40 | Get
41 | If Object.ReferenceEquals(resourceMan, Nothing) Then
42 | Dim temp As Global.System.Resources.ResourceManager = New Global.System.Resources.ResourceManager("GeometRi.Resources", GetType(Resources).Assembly)
43 | resourceMan = temp
44 | End If
45 | Return resourceMan
46 | End Get
47 | End Property
48 |
49 | '''
50 | ''' Overrides the current thread's CurrentUICulture property for all
51 | ''' resource lookups using this strongly typed resource class.
52 | '''
53 | _
54 | Friend Property Culture() As Global.System.Globalization.CultureInfo
55 | Get
56 | Return resourceCulture
57 | End Get
58 | Set
59 | resourceCulture = value
60 | End Set
61 | End Property
62 | End Module
63 | End Namespace
64 |
--------------------------------------------------------------------------------
/GeometRi/My Project/Resources.resx:
--------------------------------------------------------------------------------
1 |
2 |
3 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 | text/microsoft-resx
107 |
108 |
109 | 2.0
110 |
111 |
112 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
113 |
114 |
115 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
116 |
117 |
--------------------------------------------------------------------------------
/GeometRi/My Project/Settings.Designer.vb:
--------------------------------------------------------------------------------
1 | '------------------------------------------------------------------------------
2 | '
3 | ' This code was generated by a tool.
4 | ' Runtime Version:4.0.30319.42000
5 | '
6 | ' Changes to this file may cause incorrect behavior and will be lost if
7 | ' the code is regenerated.
8 | '
9 | '------------------------------------------------------------------------------
10 |
11 | Option Strict On
12 | Option Explicit On
13 |
14 |
15 | Namespace My
16 |
17 | _
20 | Partial Friend NotInheritable Class MySettings
21 | Inherits Global.System.Configuration.ApplicationSettingsBase
22 |
23 | Private Shared defaultInstance As MySettings = CType(Global.System.Configuration.ApplicationSettingsBase.Synchronized(New MySettings()),MySettings)
24 |
25 | #Region "My.Settings Auto-Save Functionality"
26 | #If _MyType = "WindowsForms" Then
27 | Private Shared addedHandler As Boolean
28 |
29 | Private Shared addedHandlerLockObject As New Object
30 |
31 | _
32 | Private Shared Sub AutoSaveSettings(ByVal sender As Global.System.Object, ByVal e As Global.System.EventArgs)
33 | If My.Application.SaveMySettingsOnExit Then
34 | My.Settings.Save()
35 | End If
36 | End Sub
37 | #End If
38 | #End Region
39 |
40 | Public Shared ReadOnly Property [Default]() As MySettings
41 | Get
42 |
43 | #If _MyType = "WindowsForms" Then
44 | If Not addedHandler Then
45 | SyncLock addedHandlerLockObject
46 | If Not addedHandler Then
47 | AddHandler My.Application.Shutdown, AddressOf AutoSaveSettings
48 | addedHandler = True
49 | End If
50 | End SyncLock
51 | End If
52 | #End If
53 | Return defaultInstance
54 | End Get
55 | End Property
56 | End Class
57 | End Namespace
58 |
59 | Namespace My
60 |
61 | _
64 | Friend Module MySettingsProperty
65 |
66 | _
67 | Friend ReadOnly Property Settings() As Global.GeometRi.My.MySettings
68 | Get
69 | Return Global.GeometRi.My.MySettings.Default
70 | End Get
71 | End Property
72 | End Module
73 | End Namespace
74 |
--------------------------------------------------------------------------------
/GeometRi/My Project/Settings.settings:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/GeometRiExample.CSharp/GeometRiExample.CSharp.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 | {AC37FB79-BBBA-4F6B-9BC2-0B1110936B9E}
8 | Exe
9 | Properties
10 | GeometRiExample.CSharp
11 | GeometRiExample.CSharp
12 | v4.0
13 | 512
14 |
15 |
16 |
17 | AnyCPU
18 | true
19 | full
20 | false
21 | bin\Debug\
22 | DEBUG;TRACE
23 | prompt
24 | 4
25 |
26 |
27 | AnyCPU
28 | pdbonly
29 | true
30 | bin\Release\
31 | TRACE
32 | prompt
33 | 4
34 |
35 |
36 |
37 | ..\GeometRi\bin\Debug\GeometRi.dll
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
61 |
--------------------------------------------------------------------------------
/GeometRiExample.CSharp/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using GeometRi;
3 |
4 | static class Module1
5 | {
6 |
7 |
8 |
9 |
10 | public static void Main()
11 | {
12 | // Examples of basic operations with GeometRi
13 |
14 | // Global coordinate system is created automatically and can be accessed as "Coord3d.GlobalCS"
15 | Console.WriteLine("Number of defined coordinate systems: {0}", Coord3d.Counts);
16 | Console.WriteLine();
17 | Console.WriteLine("Default coordinate system: ");
18 | Console.WriteLine(Coord3d.GlobalCS.ToString());
19 |
20 |
21 |
22 | Console.WriteLine();
23 | Console.WriteLine();
24 | Console.WriteLine("!!! Find intersection of plane with line !!!");
25 |
26 | // Define point and vector in global CS
27 | Point3d p1 = new Point3d(1, -5, -1);
28 | Vector3d v1 = new Vector3d(-2, 3, 4);
29 |
30 | // Define line using point and vector
31 | Line3d l1 = new Line3d(p1, v1);
32 |
33 | // Define plane using general equation in 3D space in the form "A*x+B*y+C*z+D=0"
34 | Plane3d s1 = new Plane3d(-2, 2, 3, -29);
35 |
36 | // Find the intersection of line with plane.
37 | // The results could be point, line or nothing, therefore get result as general object
38 | // and determine it's type.
39 | object obj = l1.IntersectionWith(s1);
40 | if (obj != null)
41 | {
42 | if (obj.GetType() == typeof(Line3d))
43 | {
44 | Console.WriteLine("Intersection is line");
45 | Line3d l2 = (Line3d)obj;
46 | Console.WriteLine(l2.ToString());
47 | }
48 | else if (obj.GetType() == typeof(Point3d))
49 | {
50 | Console.WriteLine("Intersection is point");
51 | Point3d p2 = (Point3d)obj;
52 | Console.WriteLine(p2.ToString());
53 | }
54 | }
55 |
56 | // Short variant
57 | // Will cause "InvalidCastException" if the intersection is not a point
58 | Point3d p3 = (Point3d)l1.IntersectionWith(s1);
59 | Console.WriteLine(p3.ToString());
60 |
61 | Console.ReadLine();
62 |
63 |
64 | }
65 |
66 | }
67 |
--------------------------------------------------------------------------------
/GeometRiExample.CSharp/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("GeometRiExample.CSharp")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("GeometRiExample.CSharp")]
13 | [assembly: AssemblyCopyright("Copyright © 2017")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("ac37fb79-bbba-4f6b-9bc2-0b1110936b9e")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/GeometRiExample.CSharp/app.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/GeometRiExample/GeometRiExample.vbproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 | {1C73CAA1-A41C-44C1-A1BD-2EA51ACFBEED}
8 | Exe
9 | GeometRiExample.Module1
10 | GeometRiExample
11 | GeometRiExample
12 | 512
13 | Console
14 | v4.0
15 |
16 |
17 |
18 | AnyCPU
19 | true
20 | full
21 | true
22 | true
23 | bin\Debug\
24 | GeometRiExample.xml
25 | 42016,41999,42017,42018,42019,42032,42036,42020,42021,42022
26 |
27 |
28 | AnyCPU
29 | pdbonly
30 | false
31 | true
32 | true
33 | bin\Release\
34 | GeometRiExample.xml
35 | 42016,41999,42017,42018,42019,42032,42036,42020,42021,42022
36 |
37 |
38 | On
39 |
40 |
41 | Binary
42 |
43 |
44 | Off
45 |
46 |
47 | On
48 |
49 |
50 |
51 | False
52 | ..\GeometRi\bin\Debug\GeometRi.dll
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 | True
77 | Application.myapp
78 |
79 |
80 | True
81 | True
82 | Resources.resx
83 |
84 |
85 | True
86 | Settings.settings
87 | True
88 |
89 |
90 |
91 |
92 | VbMyResourcesResXFileCodeGenerator
93 | Resources.Designer.vb
94 | My.Resources
95 | Designer
96 |
97 |
98 |
99 |
100 |
101 | MyApplicationCodeGenerator
102 | Application.Designer.vb
103 |
104 |
105 | SettingsSingleFileGenerator
106 | My
107 | Settings.Designer.vb
108 |
109 |
110 |
111 |
118 |
--------------------------------------------------------------------------------
/GeometRiExample/Module1.vb:
--------------------------------------------------------------------------------
1 | Imports System.Math
2 | Imports GeometRi
3 |
4 | Module Module1
5 |
6 |
7 |
8 | Sub Main()
9 |
10 | ' Examples of basic operations with GeometRi
11 |
12 | ' Global coordinate system is created automatically and can be accessed as "Coord3d.GlobalCS"
13 | Console.WriteLine("Number of defined coordinate systems: {0}", Coord3d.Counts)
14 | Console.WriteLine()
15 | Console.WriteLine("Default coordinate system: ")
16 | Console.WriteLine(Coord3d.GlobalCS.ToString)
17 |
18 |
19 | Console.WriteLine()
20 | Console.WriteLine()
21 | Console.WriteLine("!!! Find intersection of plane with line !!!")
22 |
23 | ' Define point and vector in global CS
24 | Dim p1 As Point3d = New Point3d(1, -5, -1)
25 | Dim v1 As Vector3d = New Vector3d(-2, 3, 4)
26 |
27 | ' Define line using point and vector
28 | Dim l1 As Line3d = New Line3d(p1, v1)
29 |
30 | ' Define plane using general equation in 3D space in the form "A*x+B*y+C*z+D=0"
31 | Dim s1 As Plane3d = New Plane3d(-2, 2, 3, -29)
32 |
33 | ' Find the intersection of line with plane.
34 | ' The results could be point, line or nothing, therefore get result as general object
35 | ' and determine it's type.
36 | Dim obj As Object = l1.IntersectionWith(s1)
37 | If obj IsNot Nothing Then
38 | If obj.GetType Is GetType(Line3d) Then
39 | Console.WriteLine("Intersection is line")
40 | Dim l2 As Line3d = CType(obj, Line3d)
41 | Console.WriteLine(l2.ToString)
42 | ElseIf obj.GetType Is GetType(Point3d) Then
43 | Console.WriteLine("Intersection is point")
44 | Dim p2 As Point3d = CType(obj, Point3d)
45 | Console.WriteLine(p2.ToString)
46 | End If
47 | End If
48 |
49 | ' Short variant
50 | ' Will cause "InvalidCastException" if the intersection is not a point
51 | Dim p3 As Point3d = CType(l1.IntersectionWith(s1), Point3d)
52 | Console.WriteLine(p3.ToString())
53 |
54 |
55 | Console.ReadLine()
56 |
57 |
58 | End Sub
59 |
60 |
61 |
62 |
63 | End Module
64 |
--------------------------------------------------------------------------------
/GeometRiExample/My Project/Application.Designer.vb:
--------------------------------------------------------------------------------
1 | '------------------------------------------------------------------------------
2 | '
3 | ' This code was generated by a tool.
4 | ' Runtime Version:4.0.30319.42000
5 | '
6 | ' Changes to this file may cause incorrect behavior and will be lost if
7 | ' the code is regenerated.
8 | '
9 | '------------------------------------------------------------------------------
10 |
11 | Option Strict On
12 | Option Explicit On
13 |
14 |
--------------------------------------------------------------------------------
/GeometRiExample/My Project/Application.myapp:
--------------------------------------------------------------------------------
1 |
2 |
3 | false
4 | false
5 | 0
6 | true
7 | 0
8 | 2
9 | true
10 |
11 |
--------------------------------------------------------------------------------
/GeometRiExample/My Project/AssemblyInfo.vb:
--------------------------------------------------------------------------------
1 | Imports System
2 | Imports System.Reflection
3 | Imports System.Runtime.InteropServices
4 |
5 | ' General Information about an assembly is controlled through the following
6 | ' set of attributes. Change these attribute values to modify the information
7 | ' associated with an assembly.
8 |
9 | ' Review the values of the assembly attributes
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 | 'The following GUID is for the ID of the typelib if this project is exposed to COM
21 |
22 |
23 | ' Version information for an assembly consists of the following four values:
24 | '
25 | ' Major Version
26 | ' Minor Version
27 | ' Build Number
28 | ' Revision
29 | '
30 | ' You can specify all the values or you can default the Build and Revision Numbers
31 | ' by using the '*' as shown below:
32 | '
33 |
34 |
35 |
36 |
--------------------------------------------------------------------------------
/GeometRiExample/My Project/Resources.Designer.vb:
--------------------------------------------------------------------------------
1 | '------------------------------------------------------------------------------
2 | '
3 | ' This code was generated by a tool.
4 | ' Runtime Version:4.0.30319.42000
5 | '
6 | ' Changes to this file may cause incorrect behavior and will be lost if
7 | ' the code is regenerated.
8 | '
9 | '------------------------------------------------------------------------------
10 |
11 | Option Strict On
12 | Option Explicit On
13 |
14 | Imports System
15 |
16 | Namespace My.Resources
17 |
18 | 'This class was auto-generated by the StronglyTypedResourceBuilder
19 | 'class via a tool like ResGen or Visual Studio.
20 | 'To add or remove a member, edit your .ResX file then rerun ResGen
21 | 'with the /str option, or rebuild your VS project.
22 | '''
23 | ''' A strongly-typed resource class, for looking up localized strings, etc.
24 | '''
25 | _
29 | Friend Module Resources
30 |
31 | Private resourceMan As Global.System.Resources.ResourceManager
32 |
33 | Private resourceCulture As Global.System.Globalization.CultureInfo
34 |
35 | '''
36 | ''' Returns the cached ResourceManager instance used by this class.
37 | '''
38 | _
39 | Friend ReadOnly Property ResourceManager() As Global.System.Resources.ResourceManager
40 | Get
41 | If Object.ReferenceEquals(resourceMan, Nothing) Then
42 | Dim temp As Global.System.Resources.ResourceManager = New Global.System.Resources.ResourceManager("GeometRiExample.Resources", GetType(Resources).Assembly)
43 | resourceMan = temp
44 | End If
45 | Return resourceMan
46 | End Get
47 | End Property
48 |
49 | '''
50 | ''' Overrides the current thread's CurrentUICulture property for all
51 | ''' resource lookups using this strongly typed resource class.
52 | '''
53 | _
54 | Friend Property Culture() As Global.System.Globalization.CultureInfo
55 | Get
56 | Return resourceCulture
57 | End Get
58 | Set
59 | resourceCulture = value
60 | End Set
61 | End Property
62 | End Module
63 | End Namespace
64 |
--------------------------------------------------------------------------------
/GeometRiExample/My Project/Resources.resx:
--------------------------------------------------------------------------------
1 |
2 |
3 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 | text/microsoft-resx
107 |
108 |
109 | 2.0
110 |
111 |
112 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
113 |
114 |
115 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
116 |
117 |
--------------------------------------------------------------------------------
/GeometRiExample/My Project/Settings.Designer.vb:
--------------------------------------------------------------------------------
1 | '------------------------------------------------------------------------------
2 | '
3 | ' This code was generated by a tool.
4 | ' Runtime Version:4.0.30319.42000
5 | '
6 | ' Changes to this file may cause incorrect behavior and will be lost if
7 | ' the code is regenerated.
8 | '
9 | '------------------------------------------------------------------------------
10 |
11 | Option Strict On
12 | Option Explicit On
13 |
14 |
15 | Namespace My
16 |
17 | _
20 | Partial Friend NotInheritable Class MySettings
21 | Inherits Global.System.Configuration.ApplicationSettingsBase
22 |
23 | Private Shared defaultInstance As MySettings = CType(Global.System.Configuration.ApplicationSettingsBase.Synchronized(New MySettings()),MySettings)
24 |
25 | #Region "My.Settings Auto-Save Functionality"
26 | #If _MyType = "WindowsForms" Then
27 | Private Shared addedHandler As Boolean
28 |
29 | Private Shared addedHandlerLockObject As New Object
30 |
31 | _
32 | Private Shared Sub AutoSaveSettings(ByVal sender As Global.System.Object, ByVal e As Global.System.EventArgs)
33 | If My.Application.SaveMySettingsOnExit Then
34 | My.Settings.Save()
35 | End If
36 | End Sub
37 | #End If
38 | #End Region
39 |
40 | Public Shared ReadOnly Property [Default]() As MySettings
41 | Get
42 |
43 | #If _MyType = "WindowsForms" Then
44 | If Not addedHandler Then
45 | SyncLock addedHandlerLockObject
46 | If Not addedHandler Then
47 | AddHandler My.Application.Shutdown, AddressOf AutoSaveSettings
48 | addedHandler = True
49 | End If
50 | End SyncLock
51 | End If
52 | #End If
53 | Return defaultInstance
54 | End Get
55 | End Property
56 | End Class
57 | End Namespace
58 |
59 | Namespace My
60 |
61 | _
64 | Friend Module MySettingsProperty
65 |
66 | _
67 | Friend ReadOnly Property Settings() As Global.GeometRiExample.My.MySettings
68 | Get
69 | Return Global.GeometRiExample.My.MySettings.Default
70 | End Get
71 | End Property
72 | End Module
73 | End Namespace
74 |
--------------------------------------------------------------------------------
/GeometRiExample/My Project/Settings.settings:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/GeometRiExample/app.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/LICENSE.txt:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2017 Sergey Tarasov
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------