CrossingCount[contour,p]
gives a count of the number of times a ray starting from the point p crosses the closed curve contour.
CrossingCount
CrossingCount[contour,p]
gives a count of the number of times a ray starting from the point p crosses the closed curve contour.
Details and Options
- CrossingCount is also known as crossing number.
- CrossingCount is typically used to determine the inclusion of a point in a polygon.
- If the closed curve contour is self‐intersecting, CrossingCount[contour,p] gives the minimal count among all rays starting from the point p.
- The closed curve contour is typically a collection of line segments Line[{{p1,p2},…,{pn-1,pn},{pn,p1}}] and must lie in a plane.
Examples
open all close allBasic Examples (1)
Scope (3)
Count how many times a ray starting from the point crosses the closed-curve contour:
ℛ = Line[{{1, 0}, {0, 2}, {-1, 0}, {0, 1}, {1, 0}}];CrossingCount[ℛ, {0, 1 / 2}]Graphics[{ℛ, Red, Point[{0, 1 / 2}]}]ℛ = Polygon[{{0.35, 0.2}, {0.9, 0.75}, {0.1, 0.55}, {0.9, 0.35}, {0.42, 0.9}}, {1, 2, 3, 4, 5}];CrossingCount[ℛ, {0.5, 0.7}]Graphics[{ℛ, Red, Point[{0.5, 0.7}]}]Polygons with GeoGridPosition:
ℛ = Polygon[GeoGridPosition[{{{-0.9950503945490105, 1.2366760550756015},
{-0.9952074890903578, 1.2369207053693891}, {-0.9952196732768064, 1.2369073327446167},
{-0.9953160063787643, 1.236848436956935}, {-0.9954141759436825, 1.2369993898475449},
{-0. ... 197645333103}, {-0.9949098578570917, 1.2368130881428654},
{-0.9948663952535768, 1.2367477711687371}, {-0.9948714472169538, 1.2367426500757825},
{-0.9949211061652593, 1.2367089232486177}, {-0.9949439717990124, 1.236746107097628}}}, "Bonne"]];CrossingCount[ℛ, {-0.995, 1.237}]Region[ℛ, Epilog -> {Red, Point[{-0.995, 1.237}]}]Applications (1)
Color points based on the crossing count of a point in the given polygon:
ℛ = DynamicModule[«3»];points = RandomReal[{0, 1}, {8000, 2}];counts = CrossingCount[ℛ, points];Graphics[{AbsolutePointSize[1], Point[points, VertexColors -> {Green, Blue, Red}[[counts + 1]] ]}]Properties & Relations (1)
WindingCount is an alternate count function:
contour = Line[{{0.35, 0.2}, {0.42, 0.9}, {0.9, 0.35}, {0.1, 0.55}, {0.9, 0.75}, {0.35, 0.2}}];{WindingCount[contour, {0.5, 0.5}], CrossingCount[contour, {0.5, 0.5}]}History
Text
Wolfram Research (2019), CrossingCount, Wolfram Language function, https://reference.wolfram.com/language/ref/CrossingCount.html.
CMS
Wolfram Language. 2019. "CrossingCount." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/CrossingCount.html.
APA
Wolfram Language. (2019). CrossingCount. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/CrossingCount.html
BibTeX
@misc{reference.wolfram_2026_crossingcount, author="Wolfram Research", title="{CrossingCount}", year="2019", howpublished="\url{https://reference.wolfram.com/language/ref/CrossingCount.html}", note=[Accessed: 12-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_crossingcount, organization={Wolfram Research}, title={CrossingCount}, year={2019}, url={https://reference.wolfram.com/language/ref/CrossingCount.html}, note=[Accessed: 12-June-2026]}