Giter Club home page Giter Club logo

samp-mp's People

Contributors

ikkentim avatar jernejl avatar zeex avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

Forkers

thomas14 nicoo34

samp-mp's Issues

[Suggestion] More IsPointIn - Figure

Used your DistancePointLine code to make some useful functions (yeah... they're in PAWN):

stock Float:Magnitude(Float:Point1[3], Float:Point2[3]) {
    new Float:Vector[3];

    Vector[0] = Point2[0] - Point1[0];
    Vector[1] = Point2[1] - Point1[1];
    Vector[2] = Point2[2] - Point1[2];

    return floatsqroot( Vector[0] * Vector[0] + Vector[1] * Vector[1] + Vector[2] * Vector[2] );
}

stock Float:DistanceFromPointToLine(Float:Point[3], Float:LineStart[3], Float:LineEnd[3], Float:Intersection[3]) {
    new Float:LineMag, Float:U;

    LineMag = Magnitude(LineEnd, LineStart);
    LineMag *= LineMag;

    if (LineMag < 0.001)
        return -1.0;

    U = (((Point[0] - LineStart[0]) * (LineEnd[0] - LineStart[0])) +
         ((Point[1] - LineStart[1]) * (LineEnd[1] - LineStart[1])) +
         ((Point[2] - LineStart[2]) * (LineEnd[2] - LineStart[2]))) / LineMag;

    if (U < 0.0 || U > 1.0)
        return -1.0;

    Intersection[0] = LineStart[0] + U * (LineEnd[0] - LineStart[0]);
    Intersection[1] = LineStart[1] + U * (LineEnd[1] - LineStart[1]);
    Intersection[2] = LineStart[2] + U * (LineEnd[2] - LineStart[2]);

    return Magnitude(Intersection, Point);
}

stock bool:IsPointInCone(Float:test_point[3], Float:base_center[3], Float:base_radius, Float:top_center[3], Float:top_radius) {
    new Float:cylinder_length = Magnitude(base_center, top_center),
        Float:intersection[3],
        Float:distance = DistanceFromPointToLine(test_point, base_center, top_center, intersection),
        Float:radius = (Magnitude(intersection, base_center) / cylinder_length * top_radius) + (Magnitude(intersection, top_center) / cylinder_length * base_radius);

    return (distance != -1.0 && distance <= radius);
}

stock bool:IsPointInCylinder(Float:test_point[3], Float:base_center[3], Float:top_center[3], Float:radius) {
    new Float:cylinder_length = Magnitude(base_center, top_center),
        Float:intersection[3],
        Float:distance = DistanceFromPointToLine(test_point, base_center, top_center, intersection),
        Float:tradius = (Magnitude(intersection, base_center) / cylinder_length * radius) + (Magnitude(intersection, top_center) / cylinder_length * radius);

    return (distance != -1.0 && distance <= tradius);
}

stock bool:IsPointInSphere(Float:test_point[3], Float:center[3], Float:radius) {
    return (Magnitude(center, test_point) <= radius);
}

main() {
    new Float:test_point[3] = {0.0, 0.0, 5.0},
        Float:form_center[3] = {0.0, 0.0, 0.0},
        Float:form_top[3] = {0.0, 0.0, 10.0};

    printf("Is it? %s", IsPointInCone(test_point, form_center, 5.0, form_top, 0.0) ? ("Yes.") : ("No."));
    printf("Is it? %s", IsPointInCylinder(test_point, form_center, form_top, 0.0) ? ("Yes.") : ("No."));
    printf("Is it? %s", IsPointInSphere(test_point, form_center, 10.0) ? ("Yes.") : ("No."));
}

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.