Shortest distance between two line segments

This is my solution in Python. Works with 3d points and you can simplify for 2d. import numpy as np def closestDistanceBetweenLines(a0,a1,b0,b1,clampAll=False,clampA0=False,clampA1=False,clampB0=False,clampB1=False): ”’ Given two lines defined by numpy.array pairs (a0,a1,b0,b1) Return the closest points on each segment and their distance ”’ # If clampAll=True, set all clamps to True if clampAll: clampA0=True clampA1=True clampB0=True … Read more

What is the difference between Type and Class?

The following answer is from Gof book (Design Patterns) An object’s class defines how the object is implemented. The class defines object’s internal state and the implementation of its operations. In contrast, an object’s type only refers to its interface – a set of requests to which it can respond. An object can have many … Read more

Conditional logging with minimal cyclomatic complexity

With current logging frameworks, the question is moot Current logging frameworks like slf4j or log4j 2 don’t require guard statements in most cases. They use a parameterized log statement so that an event can be logged unconditionally, but message formatting only occurs if the event is enabled. Message construction is performed as needed by the … Read more

Why does division by zero in IEEE754 standard results in Infinite value?

It’s a nonsense from the mathematical perspective. Yes. No. Sort of. The thing is: Floating-point numbers are approximations. You want to use a wide range of exponents and a limited number of digits and get results which are not completely wrong. 🙂 The idea behind IEEE-754 is that every operation could trigger “traps” which indicate … Read more

Recursion or iteration?

Are they more expensive than iterations? Yes they are. Many Lisp variants support the idea of a “tail-call optimisation” which allows many uses of a recursive function call to be converted into an iterative one (this is simplifying a bit). If tail-call is not supported, then a recursive function call will use progressively more memory … Read more

Acronyms in CamelCase [closed]

There are legitimate criticisms of the Microsoft advice from the accepted answer. Inconsistent treatment of acronyms/initialisms depending on number of characters: playerID vs playerId vs playerIdentifier. The question of whether two-letter acronyms should still be capitalized if they appear at the start of the identifier: USTaxes vs usTaxes Difficulty in distinguishing multiple acronyms: i.e. USID … Read more