## How to mix two ARGB pixels?

Taken from the same Wikipedia article where you got the image: Translating to values which range from 0 to 255: rOut = (rA * aA / 255) + (rB * aB * (255 – aA) / (255*255)) gOut = (gA * aA / 255) + (gB * aB * (255 – aA) / (255*255)) bOut … Read more

## Polygon Triangulation with Holes

To give you some more choices of libraries out there: Polyboolean. I never tried this one, but it looks promising: http://www.complex-a5.ru/polyboolean/index.html General Polygon Clipper. This one works very well in practice and does triangulation as well as clipping and holes holes: http://www.cs.man.ac.uk/~toby/alan/software/ My personal recommendation: Use the tesselation from the GLU (OpenGL Utility Library). The … Read more

## In MATLAB, how do I plot to an image and save the result without displaying it?

When you create the figure you set the Visibile property to Off. f = figure(‘visible’,’off’) Which in your case would be im = imread(‘image.tif’); f = figure(‘visible’,’off’), imshow(im, ‘Border’, ‘tight’); rectangle(‘Position’, [100, 100, 10, 10]); print(f, ‘-r80’, ‘-dtiff’, ‘image2.tif’); And if you want to view it again you can do set(f,’visible’,’on’)

## Bump-map a sphere with a texture map

usually rectangle texture is used for spheres texture (u,v) coordinates are used as angles for spherical coordinates. The result is that texels are bigger near equator and smaller near poles. At poles all the texels merge to single pixel. This is how to do it texturing spheres normal/bump mapping When you use these maps (color,normal,light,clouds): … Read more

## Bouncing Ball. Making it slow down at peak of height

Use ‘real’ physics for that. ball have parameters acceleration a(ax,ay,az) [m/s^2]… this is sum of all forces driving ball divided by its mass velocity v(vx,vy,vz) [m/s]… actual speed = integration of acceleration v += a * dt position p(x,y,z) [m]… actual position = integration of velocity p += v * dt radius r [m] mass … Read more

## Algorithm for drawing a 4-connected line

The following is a Bresenham-like algorithm that draws 4-connected lines. The code is in Python but I suppose can be understood easily even if you don’t know the language. def line(x0, y0, x1, y1, color): dx = abs(x1 – x0) # distance to travel in X dy = abs(y1 – y0) # distance to travel … Read more

## Three.js: What Is The Exact Difference Between Lambert and Phong?

Shane, it’s not your fault that you’re confused. Lambert is an illumination model (with a physical basis) for the light reflected off a surface, expressed in terms of the incoming illumination’s direction with respect to the surface normal at the point of incidence. Phong is a more nuanced shading model (albeit a more hacky one) … Read more

## How do you check for intersection between a line segment and a line ray emanating from a point at an angle from horizontal?

Let’s label the points q = (x1, y1) and q + s = (x2, y2). Hence s = (x2 − x1, y2 − y1). Then the problem looks like this: Let r = (cos θ, sin θ). Then any point on the ray through p is representable as p + t r (for a scalar … Read more

## How to offset a cubic bezier curve?

I hope you found my math paper useful Quadratic bezier offsetting with selective subdivision https://microbians.com/mathcode