GithubHelp home page GithubHelp logo

vefghmhassan / stl-volume Goto Github PK

View Code? Open in Web Editor NEW
3.0 1.0 0.0 9 KB

The Go code snippet calculates volume, weight, and density of 3D models from STL files, supporting both ASCII and binary formats. It features `STLCalc` for file analysis, incorporating methods for reading, volume computation, and density adjustment, useful in 3D printing and CAD applications.

License: MIT License

Go 100.00%
stl stl-algorithms stl-files stl-model stl-viewer

stl-volume's Introduction

STLCalc: STL Volume and Weight Calculator

STLCalc is a Go library designed to calculate the volume and weight of 3D objects described by STL (Stereolithography) files. It supports both binary and ASCII STL file formats, allowing users to easily analyze and manipulate 3D object data, particularly useful in 3D printing, CAD software, or similar applications.

Features File Format Support: Handles both ASCII and binary STL files. Volume Calculation: Computes the volume of STL objects. Weight Calculation: Calculates the object's weight based on volume and material density. Material Density: Allows setting custom material densities. Triangle Count: Retrieves the number of triangles in the STL file. Installation To use STLCalc, you'll need to have Go installed on your system. You can then include STLCalc in your Go project by adding the provided stlcalc.go file to your project directory.

Usage Initializing STLCalc First, initialize a new instance of STLCalc by providing the path to your STL file:

calc, err := NewSTLCalc("path/to/your/object.stl")
if err != nil {
    log.Fatalf("Failed to initialize STLCalc: %v", err)
}
defer calc.Close()

Setting Material Density

Set the density of the material (in g/cm³) for accurate weight calculations:

calc.SetDensity(1.04) // Example for ABS plastic

Calculating Volume and Weight

Calculate the volume (in cm³ or in³) and weight (in grams) of the object:

volumeCm3, err := calc.GetVolume("cm") // or "in" for cubic inches
if err != nil {
    log.Fatalf("Failed to calculate volume: %v", err)
}

weight, err := calc.GetWeight()
if err != nil {
    log.Fatalf("Failed to calculate weight: %v", err)
}

Retrieving Triangle Count

Optionally, get the number of triangles in the STL file:

trianglesCount := calc.GetTrianglesCount()

Contributing

We welcome contributions to STLCalc! Please feel free to submit issues, pull requests, or suggest features to enhance the tool's functionality.

stl-volume's People

Contributors

vefghmhassan avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.