Click here to Skip to main content
15,890,527 members
Articles / Programming Languages / C#
Article

Sharp3D.Math - A 3D math library for .NET

Rate me:
Please Sign up or sign in to vote.
4.30/5 (32 votes)
9 Jun 20041 min read 223.6K   6.6K   79   51
A 3D math library written in C#

Introduction

I started building this library as part of a C# 3D engine I am currently working on. Having noticed that there isn't any decent open-source C# library for dealing with complex math out there I decided to focus my efforts on this library and release it to the world.

More information could be found on the project's workspace at http://workspaces.gotdotnet.com/sharp3d.

Features

  • Support both single-precision and double-precision floating point types.
  • Full-featured implementation of mathematical data types including complex numbers' quaternion and various sizes of matrices and vectors.
  • Geometric data types and algorithms for 2D and 3D - distance and intersection methods, bounding volumes etc.
  • Random number and noise generation.
  • Strong-Typed collections for the library's data types.
  • Extension of standard mathematical functions, such as Cos(), Sqrt(), and Exp(), to work with vectors, matrices, and complex number classes.
  • A support library for converting between DirectX and Sharp3D.Math structures.

History

  • v1.1.1621.25560 - Update
    • Added array lists for vector structures.
    • Added a Polygon class to the Geometry3D and Geometry2D namespaces.
    • Added a Triangle structure to the Geometry3D namespace.
    • Intersection Methods : Ray to plane, AABB, OBB, Triangle and Sphere (not fully implemented yet).
    • Intersection Methods between AABB, OBB and Sphere (not fully implemented yet).
    • Added <, > , <=, >= operators to the vector structures.
    • Added IIntegrator implementations : SimpsonIntegral.
    • Implemented the Parse method for vectors and complex numbers.
    • Created Sharp3D.Math.Tests library and moved all unit testing classes there so that Sharp3D.Math is no longer dependent on NUnit.Framework.dll.
  • v1.1 - First release.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
Israel Israel
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
Questionpost on github? Pin
Member 1179891226-Oct-16 20:45
Member 1179891226-Oct-16 20:45 
Generala very useful lib.... Pin
zhaochunyan21-Apr-09 21:47
zhaochunyan21-Apr-09 21:47 
GeneralMatrix indexing for 3- and 4-dimensional matrixes is wrong Pin
Kluyg18-Nov-07 4:55
Kluyg18-Nov-07 4:55 
Generalsquare root of a complex number incorrect Pin
Chris J Saunders4-Jan-07 20:35
Chris J Saunders4-Jan-07 20:35 
GeneralRe: square root of a complex number incorrect Pin
Eric Engler13-Apr-07 10:03
Eric Engler13-Apr-07 10:03 
GeneralRe: square root of a complex number incorrect Pin
Chris J Saunders13-Apr-07 14:04
Chris J Saunders13-Apr-07 14:04 
GeneralThis saved me hours of programming Pin
vanRCAD17-Sep-06 0:30
vanRCAD17-Sep-06 0:30 
QuestionHow to Install & Use the Library Pin
Daniel P25-May-06 17:04
Daniel P25-May-06 17:04 
AnswerRe: How to Install & Use the Library Pin
Eran Kampf25-May-06 22:31
Eran Kampf25-May-06 22:31 
GeneralLibrary updates Pin
Eran Kampf10-Jan-05 6:44
Eran Kampf10-Jan-05 6:44 
GeneralRandom number generation. Pin
wout de zeeuw25-Sep-04 9:05
wout de zeeuw25-Sep-04 9:05 
GeneralRe: Random number generation. Pin
Eran Kampf25-Sep-04 10:00
Eran Kampf25-Sep-04 10:00 
QuestionWhy no credit to the Exocortex libraries this is derived from? Pin
Ben Houston19-Sep-04 11:56
Ben Houston19-Sep-04 11:56 
Hey Eran,

I was wondering why you don't give any credit to Exocortex.DSP and Exocortex.Geometry3D as the basis for your Sharp3D.Math library? I was looking through your new library and while I think the work you've done is impressive I was sort of shocked to see how much of the code I recognize from my own math libraries.

For example the following classes in Sharp3D.Math seem to be at least partially derived their counterparts in Exocortex.DSP, Exocortex.Geometry3D or Exocortex.Mathematics classes.
ComplexD -> ComplexD
ComplexF -> ComplexF
Vector3F -> Vector3D
Vector3D -> Vector3D
VectorArrayLists -> Vector3DCollection
Plane3F -> Plane3D
QuaternionD -> Quaterion
QuaternionF -> Quaterion
Matrix4F -> Matrix3D
Matrix4D -> Matrix3D
Polygon -> Polygon3D
SimpsonIntegral -> SimpsonIntegral
MathFunctions -> ( SimpleArray, ComplexArray, ComplexStats )

And every so often I notice code that is copied outrigth from the Exocortex libraries into the Sharp3D.Math library. For example the following is the GetIntersection function from Sharp3D.Math.Geometry3D.Plane:
/// <summary>
/// Determine the exact location where a given line intersects the plane
/// </summary>
/// <param name="p0">A <see cref="Vector3F"/> instance.</param>
/// <param name="p1">A <see cref="Vector3F"/> instance.</param>
/// <returns>A <see cref="Vector3F"/> instance containing the intersection location.</returns>
public Vector3F GetIntersection(Vector3F p0, Vector3F p1) {
	Debug.Assert( IsIntersection( p0, p1 ) == true );
	Vector3F Direction = p1 - p0;
	float denominator = Vector3F.DotProduct( Normal, Direction );
	if( denominator == 0 ) {
		throw new DivideByZeroException(
                   "Can not get the intersection of a plane with a line when they are parallel to each other." );
	}
	float t = ( Constant - Vector3F.DotProduct( Normal, p0 ) ) / denominator;
	return	p0 + Direction * t;
}

Here is the code from the GetIntersection function I wrote for Exocortex.Geometry3D.Plane3D:

/// <summary>
/// Determine the exact location where the given line segment intersects the plane
/// </summary>
/// <param name="pt0"></param>
/// <param name="pt1"></param>
/// <returns></returns>
public	Vector3D	GetIntersection( Vector3D pt0, Vector3D pt1 ) {
	Debug.Assert( IsIntersection( pt0, pt1 ) == true );
	Vector3D ptDirection = pt1 - pt0;
	float denominator = Vector3D.Dot( Normal, ptDirection );
	if( denominator == 0 ) {
		throw new DivideByZeroException(
                   "Can not get the intersection of a plane with a line when they are parallel to each other." );
	}
	float t = ( Constant - Vector3D.Dot( Normal, pt0 ) ) / denominator;
	return	pt0 + ptDirection * t;
}

I don't know about you but the above two code snippest look incredibly similar to me -- just the variables names have been slightly changed. This is just one instance of many uncanny similarities between your "new" code base and the ones I released a couple years back.

Thus in closing, I do congratulate you on the many new classes and polish you've put on the existing classes. Although, I would ask a favor of you: could you add back my name as well as the original BSD open source license to the classes you derived originally from my Exocortex mathematics libraries?

Kind regards,
Ben Houston
http://www.exocortex.org/ben
AnswerRe: Why no credit to the Exocortex libraries this is derived from? Pin
Eran Kampf20-Sep-04 0:15
Eran Kampf20-Sep-04 0:15 
GeneralRe: Why no credit to the Exocortex libraries this is derived from? Pin
Ben Houston20-Sep-04 5:01
Ben Houston20-Sep-04 5:01 
GeneralRe: Why no credit to the Exocortex libraries this is derived from? Pin
Eran Kampf20-Sep-04 7:06
Eran Kampf20-Sep-04 7:06 
GeneralRe: Why no credit to the Exocortex libraries this is derived from? Pin
Ben Houston20-Sep-04 7:29
Ben Houston20-Sep-04 7:29 
GeneralRe: Why no credit to the Exocortex libraries this is derived from? Pin
Eran Kampf20-Sep-04 7:52
Eran Kampf20-Sep-04 7:52 
GeneralRe: Why no credit to the Exocortex libraries this is derived from? Pin
Anonymous20-Sep-04 9:03
Anonymous20-Sep-04 9:03 
GeneralRe: Why no credit to the Exocortex libraries this is derived from? Pin
Eran Kampf20-Sep-04 9:13
Eran Kampf20-Sep-04 9:13 
AnswerRe: Why no credit to the Exocortex libraries this is derived from? Pin
Andrew Phillips25-Aug-05 22:54
Andrew Phillips25-Aug-05 22:54 
GeneralGood stuff Pin
wout de zeeuw19-Aug-04 23:32
wout de zeeuw19-Aug-04 23:32 
GeneralNew homepage Pin
Eran Kampf15-Aug-04 7:27
Eran Kampf15-Aug-04 7:27 
GeneralSome comments Pin
Colin Angus Mackay10-Jun-04 12:00
Colin Angus Mackay10-Jun-04 12:00 
GeneralRe: Some comments Pin
Eran Kampf10-Jun-04 12:18
Eran Kampf10-Jun-04 12:18 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.